UDP packets from server to client

Started by
3 comments, last by Wilhelm van Huyssteen 10 years, 11 months ago

Hi.

my game uses an UDP and a TCP connection to its server. Some data gets sent over UDP and some over TCP both from server to client and client to server.

Sending UDP packets from client to server is never a problem since the server is never behind some arbitrary router that's not in my control but what about the other way around? Can I expect to lose potential players if I use UDP from server to client or can I accept that virtually 100% of routers out there will be able to properly deliver the packets back to the client. Using UDP from server to client gains me little so its not worth it at all if I'm blocking out even a small amount of players.

Thanks in Advance!

Advertisement

I use UDP in both directions.

I've tested at least 20 different places, including coffee shops, libraries, restaurants, 3g/4g cellular and never had a problem with firewalls/router incompatibility. Maybe my sample size is too small, I'd really like to have about 200 different places tested before calling it a day (that's what Beta is for), but that has been my experience.

While I haven't hit any router issues yet, I certainly have seen differences in packet loss and latency. A couple Starbucks location are the worse: they average about 15% packet loss, 1200ms ping.

Can I expect to lose potential players if I use UDP from server to client or can I accept that virtually 100% of routers out there will be able to properly deliver the packets back to the client.

Not 100%, but a very high percentage. There is a Wikipedia article that covers the four major types of NAT traversal.

For almost all NAT classes, if the NAT-protected client sends an outgoing message to public address, then for a brief (configurable) time that machine can send messages back on the same address:port pair. It does not matter if this is TCP or UDP for most devices.

Some strict environments, such as certain corporate and government systems, will lock down NAT traversal. Also some badly-configured devices will prevent NAT traversal when it is wanted.

Most consumer and corporate NAT devices will let the communications go through. Just make sure they are always on the same address:port pair and the connection is kept active.

On the few that it won't work those people should already know about the restrictions.

If the server is publicly available, then any client that can send UDP packets out, will receive them back in, barring outright bugs in their network. If this wasn't true, then the DNS service wouldn't work.
The reason this works is that router/firewall/gateways implement NAT, where, once a packet goes out, a response to that packet will be routed back in. All the server has to do is to respond to the incoming packet using sendto() to the address that the packet had when you called recvfrom().
enum Bool { True, False, FileNotFound };

Thnx!

This topic is closed to new replies.

Advertisement