P2P And C#
| This article describes the simple approach to design a peer to peer network.
The figure1 shown below gives a general idea how p2p works. Although there are many other types where index server or central servers are not required , or can be eliminated so client talk directly to other clients. The P2P concept generally consists of a central Index server. This server does not contain any files, physically. It only maintains the information about the users who are logged on to the network, the IP address of the client and the list of files shared at any given moment by a user. The client and the server communicate with each other over a socket connection using simple commands. When a client "A" wants to search for files shared by other clients on the P2P network
Once the Client "A" selects the download option, Client "A" makes a socket connection to the Client "B" using the IP address returned by search. You can define any port that you wish to listen at. For a list of TCP ports and what port numbers that can be used click here
Such a P2P network can be used to share any type of file. It can be used for your local network or a global network. For more information about Firewall and SOCKS click here |
|
The C# language make life very easy with the help of the TCPListener and the TCPClient classes. Here is a listing of the transfer class .. public MyTcpListener(int port) : base(port) } /// <summary> public Transfer() this.tcpl = new MyTcpListener(port); public void TransferShutdown() public void ListenForPeers() Encoding ASCII = Encoding.ASCII;
String filename; public void DownloadToClient(String server, string remotefilename, string localfilename) OptionsLoader ol = new OptionsLoader();
IPEndPoint ep = new IPEndPoint(addr[0], port); // Get the stream // Read the stream and convert it to ASII tcpc.Close(); |




22. Jul, 2006 by 







No comments yet... Be the first to leave a reply!