🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

recvfrom() ?

Started by
5 comments, last by MadProgrammer 22 years, 7 months ago
does recvfrom() let you specify who u wana recv from or does it just tell u who you did recv from?
Advertisement
tells you who the incomming packet is from
so, in a multiplayer server, u only have 1 socket if you''re doing UDP?
Yes, this is one of the benifits of using a UDP server - you can use one socket to send/receive all the incomming packets and process them accordingly. The recvfrom function tells you which client the packet has come from. The other main alternative, TCP server, has a listening socket which then creates a new socket for every connected client. This becomes more complicated to manage within the server program.

This is obviously an oversimplification of the situations but gives an idea of the differences.

Henry
HenryLecturer in Computer Games TechnologyUniversity of Abertay DundeeScotlandUK
quote: Original post by henryx
The other main alternative, TCP server, has a listening socket which then creates a new socket for every connected client. This becomes more complicated to manage within the server program.

This is obviously an oversimplification of the situations but gives an idea of the differences.


At least with TCP, you don''t have to check for lost or out-of-order packets.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
I agree with you Fruny, that with TCP you don''t need to check for lost or out-of-order packets - but it may be that the overheads associated with doing this in UDP are less than managing all the sockets in TCP.

This is probably a discussion that could go on for a long time:
ie advantages/disadvantages of using TCP/UDP! Any contributions?
HenryLecturer in Computer Games TechnologyUniversity of Abertay DundeeScotlandUK
You can use connect() and recv()/send() as normal using UDP sockets which you may find easier for the clients code. Then use sendto() and recvfrom() at the server to handle the multiple clients over the one port.

UDP is faster than TCP due to the fact there is no guarantee of the packet arriving or arriving in order. It is however, relatively easy to manage packet ordering and guaranteed delivery using your own protocol where as with TCP you HAVE to have guaranteed and ordered delivery. There are numerous arguments about the merits of each all over this board but it boils down to a general consensus that UDP is quicker and with a proper implementation, ''better'' than TCP.

This topic is closed to new replies.

Advertisement