non constant port?
HELLO. i was always wondering about the option to change my server's listening port on some games, or a bittorrent client for example, or anything else like that. well, i didn't really wonder about it, i more of wondered how the other side of knows what port to connect to? let's say i'm using winsock because that's the only thing i know. const int X = 27152; all of the lovely basic tutorials out there show that the servers open a socket on port X and the client connects to that same port X. so how does these games, and my bittorrent client, and my IM-client, and everything in the world, does it?
--Amir
Either both the server and client know the port (because it is known and fixed), or like BT, when you connect to the tracker, it tells you the IP and port of all the people connected.
There is also the "SRV" record type in DNS, where you can register an IP address and port number for a specific name in DNS, and someone querying for that record kind will receive the tuple back.
Of course, the standard host resolver interface (gethostbyname()) doesn't let you query for SRV records, which means it's never been that popular. (In fact, it also doesn't let you query MX or any other record kind than recursively found A records...)
Of course, the standard host resolver interface (gethostbyname()) doesn't let you query for SRV records, which means it's never been that popular. (In fact, it also doesn't let you query MX or any other record kind than recursively found A records...)
enum Bool { True, False, FileNotFound };
Ports are either fixed for applications, or the server ports and IP are made public and stored in a server browser somewhere on the web. Since on some applications you need to know who is online and who isn't it makes sense, but it's more logistics, since you have to maintain server browsers and their mirrors. Servers like Counterstrike, Quake, ect... are made public and when you create a server, it reports itself to the server browser. Then clients query the browser for IP and port (and other stuff, like password protected, number of players, ...) to connect to a specific game. That server browser place can do much more, such as CD-key checks, storing your player profile (steam), check if your friends are online....
For IMs, I'm not sure, but I would guess they do the same. For bittorrent, I'm not familliar with it.
So, if you create an application, then you might have a problem getting people connecting to your server, if they don't know it exists, unless you maintain a database of active servers. You can't just 'search' the internet, like you would search a hard drive for a file.
For IMs, I'm not sure, but I would guess they do the same. For bittorrent, I'm not familliar with it.
So, if you create an application, then you might have a problem getting people connecting to your server, if they don't know it exists, unless you maintain a database of active servers. You can't just 'search' the internet, like you would search a hard drive for a file.
Everything is better with Metal.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement