Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


A few questions about UDP sockets


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 OandO   Members   -  Reputation: 782

Like
0Likes
Like

Posted 05 August 2013 - 10:15 AM

I've been working on fairly simple client-server setup for a game, using UPD (It's an arena shooter with lots of moving objects) and doing raw socket programming in C. I know how to create sockets, how to send, receive and process packets and whatnot, and at the other end I know what I want to send, who to and how often. However I've got a fairly substantial gap in my knowledge about the general layout I should be using:

 

Should I be using separate sockets on the server for each client, what are the advantages/disadvantages of this over a single socket for everyone?

 

Should I have separate inbound/outbound sockets? I believe this is a requirement for TCP, not sure how UDP deals with it though. I know using one socket for both in and out works, just not sure if it's a good way of doing things.

 

How do I allow any combination of clients and server using IPv4 and IPv6 to connect to each other?

 

Perhaps I'm just not searching for the right terms, but I'm having difficultly finding resources and this bit-in-the-middle sort of thing, so any help would be great!



Sponsor:

#2 markr   Crossbones+   -  Reputation: 1653

Like
0Likes
Like

Posted 05 August 2013 - 04:01 PM

>>> Should I be using separate sockets on the server for each client, what are the advantages/disadvantages of this over a single socket for everyone?

 

You can use a single socket for everyone. It probably makes things slightly easier.

 

>>> Should I have separate inbound/outbound sockets? I believe this is a requirement for TCP, not sure how UDP deals with it though. I know using one socket for both in and out works, just not sure if it's a good way of doing things.

 

Sockets are bidirectional. This includes UDP and TCP. Using the same socket for rx and tx is definitely a good idea (in fact, NAT really depends on this for UDP to work at all)

 

>>> How do I allow any combination of clients and server using IPv4 and IPv6 to connect to each other?

 

An IPv6 socket allows an IPv4 client to connect to it on a dual-stack host. It does this by using the ipv4-in-ipv6 addresses, i.e. ::ffff:1.2.3.4 addresses (at least on Linux). Port numbers are the same. Multicasting is a bit dubious, I recommend that you use separate sockets for ipv4 and ipv6 if you're multicasting.

 

However, it's not possible for an ipv4-only host to talk to an ipv6-only host, but this is unlikely to be a problem (yet) as ipv6-only hosts mostly only exist in test-labs.

 

---

 

In general I think you'll find making the game work properly is much more of a problem than low-level socket stuff. You should probably think about that.



#3 OandO   Members   -  Reputation: 782

Like
0Likes
Like

Posted 08 August 2013 - 06:38 AM

Thank you, some very useful information there! Just one question:

 

An IPv6 socket allows an IPv4 client to connect to it on a dual-stack host. It does this by using the ipv4-in-ipv6 addresses, i.e. ::ffff:1.2.3.4 addresses (at least on Linux). Port numbers are the same. Multicasting is a bit dubious, I recommend that you use separate sockets for ipv4 and ipv6 if you're multicasting.

 

Dubious in what sense?



#4 markr   Crossbones+   -  Reputation: 1653

Like
0Likes
Like

Posted 08 August 2013 - 07:22 AM

Thank you, some very useful information there! Just one question:

 

An IPv6 socket allows an IPv4 client to connect to it on a dual-stack host. It does this by using the ipv4-in-ipv6 addresses, i.e. ::ffff:1.2.3.4 addresses (at least on Linux). Port numbers are the same. Multicasting is a bit dubious, I recommend that you use separate sockets for ipv4 and ipv6 if you're multicasting.

 

Dubious in what sense?

 

If you use IPv6 sockets, and want to use IPv4 multicasting, it might be easier (particularly cross-platform) to use a separate socket for v4 and v6. Under Linux it is possible to do this, but only if you use an IPv4 setsockopt on the IPv6 socket. The (v6) socket can then get v4 multicasts, which is useful. But if you need it to work cross-platform then you probably can't guarantee this behaviour, and I'd strongly recommend using different sockets and different port numbers for v4 and v6 (different port numbers, so that your v6 socket won't receive any of your v4 datagrams)

 

Mark






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS