CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Oct 2004
    Posts
    35

    Single UDP socket, multiple connections

    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'.
    Last edited by Shambler; May 23rd, 2006 at 08:57 AM.

  2. #2
    Join Date
    Nov 2002
    Location
    California
    Posts
    4,556

    Re: Single UDP socket, multiple connections

    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

  3. #3
    Join Date
    Oct 2004
    Posts
    35

    Re: Single UDP socket, multiple connections

    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!

  4. #4
    Join Date
    Feb 2008
    Posts
    3

    Re: Single UDP socket, multiple connections

    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?

  5. #5
    Join Date
    May 2001
    Location
    Germany
    Posts
    1,158

    Re: Single UDP socket, multiple connections

    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.

  6. #6
    Join Date
    Feb 2008
    Posts
    3

    Re: Single UDP socket, multiple connections

    ok

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured