🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

UDP question

Started by
4 comments, last by haigu 23 years, 5 months ago
I''m using UDP in my multiplayer game, and have two questions: 1. If all the clients send datagrams to the same server port(usually the wellknown port),wouldn''t it easily cause packets to get lost, because of the limited buffer? In Richard Stevens'' book, UNIX Network Programming, says we can create a new socket, bind it to another port and let the client communitate with that socket later. Does this method help? and how to implement it with Winsock? 2. Is connected UDP socket good for multiplayer games?
Ò»½«¹¦³ÉÍò¹Ç¿Ý
Advertisement
1. If you''re not reading fast enough you will drop packets. This is true regardless of how many UDP sockets you''re using.

2. Yes

-Mike
1) That''s true. But then, using up lots of ports is bad technique IMO.

2) The only two differences between connected and unconnected UDP BSD-sockets:
- unconnected sockets don''t report ICMP messages (like packet denied), at least according to the original BSD definition; on Linux machines they are reported even on unconnected sockets
- a connected UDP socket can only send/recv to/from one host

So yes, especially if you allocate one socket for every connection you could use connected sockets.

cu,
Prefect

---
Sanity is the trademark of a weak mind.
Widelands - laid back, free software strategy
Thanks for the reply, I''ll look into connected sockets then

Another question:
Why do you think using lots of ports is bad?
In my case, I''m targeting a server (or several servers) that may host dozens or hundreds of players, so it may use up as many ports.
Ò»½«¹¦³ÉÍò¹Ç¿Ý
Using lots of sockets is bad because it doesn''t scale. Lots of sockets require lots of resources to support them (buffers, etc). If you''re trying to scale to lots of clients then resources are going to be tight anyway and you''re just making it harder on yourself.

Plus some api''s are limited in the number of sockets they can work with at once. e.g. In Windows select() only does 64 sockets. I wouldn''t be suprised if Unix has similiar types of limits.

-Mike
1) Unix''s got a limit of 1024 sockets in the FD_SET: simple & efficient bit field (dword fd_set[32]).

2) Just forget stream sockets (connection oriented) for communication. In a MMO you''d have to have 1 socket per connected client on the server side!!
- stream sockets are way too slow for real-time gaming!
- use the stream socket (tcp) to connect to the server, get a new port number for datagram (udp) communications,
- while playing, just delete the stream socket (helpless at this time),
- if server needs to send private & vital info to one client, it should then connect itself (stream) to the client, and transfer the data once connected, (or you implement a secured datagram protocol)
- server should assign datagram ports dynamically, based on the load, so as to limit the number of opened datagram sockets. If a socket gets flooded too often, create a new one, and communicate its new port to some of the clients.

Hope that helps a little...


And, haigu, just to make things clear:
TCP <==> stream socket <==> connection oriented
UDP <==> datagram socket <==> connectionless

This topic is closed to new replies.

Advertisement