Jump to content
  • Advertisement
Sign in to follow this  
Crazyfool

SOCKET number bounds

This topic is 4173 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I am wondering if there is a general SOCKET numerical bounds.. What I mean is, I've noticved a socket value is somewhere between 3800-4000 pretty consisitently, and I want to know if it can be pretty much any unsigned int. What I want to do is use the sockets as an index, sorta, and basically subtract 3800 or so from each and then thats the index of an array. I think that can increase my servers speed without going too intense, but if this wont work right then I guess I'll have to use a more complex algorithm. Here's the reason: I have to get player info by the socket (avoiding a player sending name, or other stuff) and want to make it quick as possible. One solution I had was just have the server send the client's ID depending on when he joined and then just have the client send that each time, which would only add 2-3 bytes per send, though I want to save bandwith as much as possible. Thanks!

Share this post


Link to post
Share on other sites
Advertisement
Sockets are implementation dependent. This is especially true between unixlikes where sockets are just file descriptors which are just ints and winsock where sockets are not intertwined with files.

You also might want to keep in mind that all your clients might not always want to connect via sockets and not intertwine them too strongly as an ID or key.

Share this post


Link to post
Share on other sites
Quote:
Original post by Telastyn
Sockets are implementation dependent. This is especially true between unixlikes where sockets are just file descriptors which are just ints and winsock where sockets are not intertwined with files.

You also might want to keep in mind that all your clients might not always want to connect via sockets and not intertwine them too strongly as an ID or key.


Thanks! though, the server uses sockets, and doesnt that gurantee that every person connecting will use sockets?

maybe? haha

Share this post


Link to post
Share on other sites

>What I mean is, I've noticved a socket value is somewhere between 3800-4000
>pretty consisitently, and I want to know if it can be pretty much any
>unsigned int.
I wouldn't assume that as a fact. Yesterday I was playing around with
my socket implementation and got ports around 1900 - who knows, maybe
next time it'll give a value in the 50.000 range...

Anyway, if you have a good container, I'm pretty sure you don't need to
do stuff like subtract the lowest expected port number.

Regards

Share this post


Link to post
Share on other sites
It can be a value in a very large range, not just the range of 3800-4000 [matter of a fact, it is legal to be ANY value for the data type it is, except for 'INVALID_SOCKET']. If you want to see a socket outside of the range of 3800-4000, make 201 sockets :D

It is HIGHLY advised [though you can do whatever you want, and it's unlikely there'll be someone there to stop you] that you do NOT use socket ID's as indexes, for quite a range of reasons. First off, one socket might have the value of 3800, and the next just as easily could have the value of 12000. Secondly, one socket could have a value of 3800, and when you release that socket and make another one, it very well could also have the value 3800 [yielding the same index], which may very well cause confusion regarding packets that have been read, but maybe not processed yet, or processed but not quite responded to yet [thus possibly sending the response to the new socket].

The server implementation I'm currently using supports 65000'ish concurrent connections, and those socket numbers are all over the place, with small gaps in the numbers here and there, maybe some big gaps, then thousands sequentially. Trying to squeeze an index pattern out of number soup is not easy.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!