开发者

How does a client find the port number of a server?

开发者 https://www.devze.com 2022-12-25 13:35 出处:网络
I am currently learning about basic networking in java. I have been playing around with the server and client relationship between two of my computers.

I am currently learning about basic networking in java. I have been playing around with the server and client relationship between two of my computers. However, I cannot figure out how distributed programs (say, a videogame), can not only find the 'host' computer, but also the port number on which the server is running in order to create a Socket between the two computers. The only way I really see to create a Socket is with an already known IP Address, and with a known port number.

How do you search a LAN network for another computer (host) searching for clients?

How do you determine what port the server is located on without 'pinging' all available ports for a response (which, I understand, is bad form... Som开发者_如何学编程ething about 'server attack'...)?

In such a situation as a video game, there can be any number of computers on the same network, and any number of them might be attempting to host, or otherwise running the application. Any other important information, or perhaps reference to a more detailed tutorial than the one I am using, regarding making connections on so very little information on the client side would be appreciated.

Many thanks,

Jonathan


Normally services/schemes have a given port number or range of port numbers that they use (HTTP uses 80, SSH uses 22, etc.). Additionally, they may connect to a "master" server in order to announce their presence and learn about other nodes (e.g., Battle.net).

Neither of these is strictly needed if Zeroconf is used (via Bonjour, Avahi, etc.). Zeroconf allows machines to do multicast DNS on a LAN instead of the pointcast mechanism traditionally used for DNS. This allows them to discover machines across the network that also support mDNS, and to discover services running on them.

0

精彩评论

暂无评论...
验证码 换一张
取 消