Hi, everyone!
I'm doing a p2p streaming project. This project is actually about : the server and client will connect first (socket created), after connect then client will receive the IP address of another client from server, then those 2 clients connect together and start streaming.
I can write the program that let server and client connect, but p2p I don't know how to do.
1. In 1 program can create 2 sockets?
2. Hope you can help me with a sample code of p2p, connect and/or streaming. I already do a search on Google but only see server-client version (this kind of thing I can do).

Thanks a lot for your help and your time.

Like for example, getting the source code for existing p2p clients?

"p2p" isn't magic. It's just a pair of sockets (usually) and an understanding of the protocol (usually the hard part) of sending and receiving the right information, and knowing what to do with it.

Let one (anyone) client is appointed "p2p server" and another client is appointed "p2p client" by the server.

I can write the program that let server and client connect

That's all - you know the right solution. After p2p connection establishing they will have only p2p protocol troubles as was mentioned by Salem...

Yes...I understand what you all say, but the thing I'm not very clear is, how they decide who will be server and who will be client. Like the server-client version, the server must do SOCKET,BIND, LISTEN, ACCEPT,CONNECT, but client need to CONNECT only. (I'm using TCP). Now the client-client version, one can be server to another one, and can be client to another one also. So...how can I write the code for it? Think that there's another way to do, where peer just send data to another peer through the socket. I'm not sure how to implement. Can you suggest any method for me, or any sample? Thanks

There is no "server" or "client", that's why it's called "peer" to "peer". They're both equal to each other.

Listen on a port for anyone who wants to talk to you, and be a "server" to those connections. And attempt to connect to other sites and be a "client".

> So...how can I write the code for it?
The same way that you would for any s/w which has multiple sockets open. Use select() to wait for any activity on any of the open sockets, then deal with any data that arrives, or send any pending data which needs to be sent.

My suggestion with (quoted!) "p2p server" and "p2p client" was retlated to peer-to-peer connection stage: it's a common way to go in brokered P2P systems (one peers connects to another with server supported mutual seacrh stage). Client and server are roles, not only fixed application architectures. Look at the original post: the author has a code to establish TCP connection. OK, it's possible to reuse this code for p2p connection.

After that peers have dual TCP channel - it's enough for peer-to-peer communications. It's the other story what's data exchange protocol used. May be they will establish another links, will start another processes or threads...

Well... Thanks for help from you all. I will try select(). I'm quite new to this p2p concept, that's why I got confused with server and client.

This article has been dead for over six months. Start a new discussion instead.