UDP multiple sockets?
I'm just starting networking programming and need to know if a server using UDP needs multiple sockets for multiple connections? I know it doesn't really make a connection though but I'm just curious if you had to people trying to connect right at the same time or something.
Artist 1st - Programmer 2nd(I'll get some material linked here sometime to support these claims, haha)
Nope, a single socket is fine. That's one of the benefits of UDP. On the other hand, as you pointed out, if you were to get 2 packets at the EXACT same time, chances are good the second packet would just be dropped.
Cheers!
Cheers!
Jeromy Walsh
Sr. Tools & Engine Programmer | Software Engineer
Microsoft Windows Phone Team
Chronicles of Elyria (An In-development MMORPG)
GameDevelopedia.com - Blog & Tutorials
GDNet Mentoring: XNA Workshop | C# Workshop | C++ Workshop
"The question is not how far, the question is do you possess the constitution, the depth of faith, to go as far as is needed?" - Il Duche, Boondock Saints
Sr. Tools & Engine Programmer | Software Engineer
Microsoft Windows Phone Team
Chronicles of Elyria (An In-development MMORPG)
GameDevelopedia.com - Blog & Tutorials
GDNet Mentoring: XNA Workshop | C# Workshop | C++ Workshop
"The question is not how far, the question is do you possess the constitution, the depth of faith, to go as far as is needed?" - Il Duche, Boondock Saints
Do I need to listen when using UDP?
Artist 1st - Programmer 2nd(I'll get some material linked here sometime to support these claims, haha)
Quote:
if you were to get 2 packets at the EXACT same time, chances are good the second packet would just be dropped
This is just not true. First, you can't, actually, receive two packets at the EXACT same time, unless you have two network cards connected to two physical circuits -- and, in that case, the system can still receive two packets simultaneously just fine.
Even if your switch receives two packets for your computer at once, there's often sufficient queuing in the switch to deal with the full throughput of the uplinks.
Dropping typically happens when buffers and queues overflow. This typically is more likely to happen on a router upstream in the internet, than on your computer. For example, the ISP end of your DSL or cable connection will drop packets when too many are coming in (i e, you're trying to receive more data than your bandwidth can fit).
However, if you receive a flood of data (lots of packets), and fill up the input buffer in the kernel, without reading from the socket for a while, you'll start dropping packets. Thus, when using a single UDP socket where some operations may take a lot of time, either use a thread to poll the socket, or ioctl() to make the read buffer really big.
enum Bool { True, False, FileNotFound };
Quote:
Original post by hplus0603:
This is just not true. First, you can't, actually, receive two packets at the EXACT same time, unless you have two network cards connected to two physical circuits -- and, in that case, the system can still receive two packets simultaneously just fine.
Uhh, ok. I Guess I'm wrong. While I was just trying to illustrate that it was unlikely he'd receive two packets at the EXACT same time, I figured it was because the NIC wouldnt handle it, but it turns out it's just impossible to get two packets at the EXACT same time...My bad. Thanks hplus for correcting me.
And unless hplus says otherwise, no, you dont need to listen() for UDP sockets, that's only for stream based connections.
Cheers!
Jeromy Walsh
Sr. Tools & Engine Programmer | Software Engineer
Microsoft Windows Phone Team
Chronicles of Elyria (An In-development MMORPG)
GameDevelopedia.com - Blog & Tutorials
GDNet Mentoring: XNA Workshop | C# Workshop | C++ Workshop
"The question is not how far, the question is do you possess the constitution, the depth of faith, to go as far as is needed?" - Il Duche, Boondock Saints
Sr. Tools & Engine Programmer | Software Engineer
Microsoft Windows Phone Team
Chronicles of Elyria (An In-development MMORPG)
GameDevelopedia.com - Blog & Tutorials
GDNet Mentoring: XNA Workshop | C# Workshop | C++ Workshop
"The question is not how far, the question is do you possess the constitution, the depth of faith, to go as far as is needed?" - Il Duche, Boondock Saints
thanks, I guess that answers the question to the new thread I started
EDIT: But if I don't listen() how do I know who to recieve data from with recvfrom()?
EDIT: But if I don't listen() how do I know who to recieve data from with recvfrom()?
Artist 1st - Programmer 2nd(I'll get some material linked here sometime to support these claims, haha)
Quote:
You can have a single IN and a single OUT UDP port.
There is no advantage to having a separate OUT UDP port, and in fact one disadvantage: it will make your application much less compatible with NAT firewalls/routers.
Quote:
if I don't listen() how do I know who to recieve data from with recvfrom()
What does the man page for recvfrom() say? (Hint: there's a reason it's called recvfrom()).
Btw: jwalsh is right: you cannot listen() on a datagram socket.
enum Bool { True, False, FileNotFound };
I have another problem gethostbyname() isn't working and I have no idea why.. here's what I'm doing just for testing
struct hostent *h;
h=gethostbyname("www.yahoo.com");
when I look at the values of h in the debugger there's nothing.
EDIT: nevermind, got it working.
struct hostent *h;
h=gethostbyname("www.yahoo.com");
when I look at the values of h in the debugger there's nothing.
EDIT: nevermind, got it working.
Artist 1st - Programmer 2nd(I'll get some material linked here sometime to support these claims, haha)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement