PEER
TO PEER
- Peer-to-peer (P2P) is a decentralized communications model in which each party has the same capabilities and either party can initiate a communication session.
- Unlike the client/server model, in which the client makes a service request and the server fulfills the request, the P2P network model allows each node to function as both a client and server.
- P2P systems can be used to provide anonymized routing of network traffic, massive parallel computing environments, distributed storage and other functions.
- Most P2P programs are focused on media sharing and P2P is therefore often associated with software piracy and copyright violation.
- In its simplest form, a peer-to-peer (P2P) network is created when two or more PCs are connected and share resources without going through a separate server computer.
- A P2P network can be an ad hoc connection—a couple of computers connected via a Universal Serial Bus to transfer files.
- A P2P network also can be a permanent infrastructure that links a half-dozen computers in a small office over copper wires.
- Or a P2P network can be a network on a much grander scale in which special protocols and applications set up direct relationships among users over the Internet. .
P2P ENVIRONMENT
·
In a P2P environment, access rights are governed by setting
sharing permissions on individual machines.
- if User A's PC is connected to a printer that User B wants to access, User A must set his machine to allow (share) access to the printer.
- Similarly, if User B wants to have access to a folder or file, or even a complete hard drive, on User A's PC, User A must enable file sharing on his PC.
- Access to folders and printers on an office P2P network can be further controlled by assigning passwords to those resources
Navigating a P2P Network
This
diagram shows how a P2P network operates. The solid lines indicate physical,
hard-wired network cables. The dotted lines indicate that each PC can
communicate and share files with every other PC on such a network. A printer
attached to one PC can be used by other PCs on the network—if that printer’s PC
allows such use.
- Centralized: This is when a central server keeps track of where the data is located among peers
- Local: This is when each peer keeps track of its own data
- Distributed: This is when the data references are maintained by multiple peers
P2P FILE SHARING:
SENDER
import java.net.*;
import java.io.*;
public class Server {
public static void main (String [] args )
throws IOException {
ServerSocket serverSocket = new
ServerSocket(15123);
Socket socket = serverSocket.accept();
System.out.println("Accepted
connection : " + socket);
File transferFile = new File
("D:\\P2PFILE\\SENDER.txt");
byte [] bytearray = new byte [(int)transferFile.length()];
FileInputStream fin = new
FileInputStream(transferFile);
BufferedInputStream bin = new
BufferedInputStream(fin);
bin.read(bytearray,0,bytearray.length);
OutputStream os =
socket.getOutputStream();
System.out.println("Sending Files to
Client...");
os.write(bytearray,0,bytearray.length);
os.flush();
socket.close();
System.out.println("File transfer
complete");
}
}
P2P: CLIENT
import java.net.*;
import java.io.*;
public class Client {
public static void main (String []
args ) throws IOException {
int filesize=1022386;
int bytesRead;
int currentTot = 0;
Socket socket = new Socket("127.0.0.1",15123);
byte [] bytearray = new byte
[filesize];
InputStream is = socket.getInputStream();
FileOutputStream fos = new
FileOutputStream("D:\\P2PFILE2\\RECEIVED.txt");
BufferedOutputStream bos = new BufferedOutputStream(fos);
bytesRead = is.read(bytearray,0,bytearray.length);
currentTot = bytesRead;
do {
bytesRead =
is.read(bytearray, currentTot,
(bytearray.length-currentTot));
if(bytesRead >= 0) currentTot +=
bytesRead;
} while(bytesRead > -1);
bos.write(bytearray, 0 , currentTot);
bos.flush();
bos.close();
socket.close();
}
}.
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.