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

廉价感情. 提交于 2019-12-11 21:22:02

问题


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... Something 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


回答1:


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.



来源:https://stackoverflow.com/questions/2558363/how-does-a-client-find-the-port-number-of-a-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!