Click to See Complete Forum and Search --> : Single UDP socket, multiple connections


Shambler
May 23rd, 2006, 08:55 AM
I'm coding a game server query for UT2004 and I have my program sending a server-info query via UDP to about a dozen servers.

I have one single UDP socket sending all the data at the same time just fine, and Ethereal shows me all the servers are sending query results back...BUT it appears that I need to create multiple sockets, one set for each server IP, so that I can receive the data in the code.

What I originally attempted to do was have just one UDP socket, receiving all data from each different IP....however this only works for sending and not receiving, does anyone know how I could do that? (perhaps a special socket option?)

Thanks.


EDIT: I know the topic name is a bit misleading, as UDP doesn't use 'connections'.

MikeAThon
May 23rd, 2006, 11:51 AM
For UDP, the docs say that you should be able to recvfrom() multiple different IPs on a single socket unless you have called connect() for that socket, in which case all datagrams from a source different from the connected-to socket will be discarded/ignored.

Did you call connect()?

Mike

Shambler
May 23rd, 2006, 12:11 PM
Ah yes, I did :) (didn't know using Connect with UDP sockets would do that)

The reason I used 'Connect' was so that I could send data to a specific IP and port, after just checking the help file again I've now realised I should have been using SendTo instead of Connect and Send ;)


Problem resolved, thanks!

finimits
February 24th, 2008, 12:11 PM
Hello,

This is a similar question.
Can anyone explain when you would use the connect() statement with UDP ?
Is it more efficient or something?

How much data can a single port handle? If I want to send many messages from one pc to another at the same , do I have to

1) create socket
2) bind
3)connect

for each individual type of message?

If not, then how do I handle different messages on the receive and send sides?

Richard.J
February 24th, 2008, 03:13 PM
I think it is common sense not to "hijack" a thread. Please post your question in a separate thread and you might get an answer.

finimits
February 24th, 2008, 03:56 PM
ok