Archived

This topic is now archived and is closed to further replies.

NetworkN00b

Peer to Peer using TCP

Recommended Posts

I was thinking of connecting to the other sockets eveytime when each clients sends a packet to the other clients, wouldn't that be slow? If so how should I do peer to peer using TCP? [edited by - NetworkN00b on January 4, 2004 10:02:10 PM]

Share this post


Link to post
Share on other sites
Once you have a socket connection established it becomes a two way path for data. So if you just have two people you could use that single data pathway to send and recv your data. A socket isn''t closed unless you call the CloseSocket(SOCKET ) function or until main dies.

The problem comes with the send and recv functions, both are blocking calls so unless you have a set point where you are going to update the data one of the clients will freeze while waiting for the other client to send data, you''d have to do asynchronous socket calls unless you have a set update point.

Share this post


Link to post
Share on other sites
If on Win32 you can use WSAAsyncSelect (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/wsaasyncselect_2.asp) to let Win32 send you messages for network events, therefore unblocking the code.

You may also find UDP useful (where you can send a packet from point A to point B without needing to initiate a connect), but then that brings in a whole host of additional problems (most notably that with UDP there is no guarentee that a packet will get there, and no guarentee that the packets sent will arrive in the same order)

Share this post


Link to post
Share on other sites