客户端如何找到服务器的端口号? [英] How does a client find the port number of a server?

查看:211
本文介绍了客户端如何找到服务器的端口号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在学习Java中的基本网络。
我一直在玩两个我的电脑之间的服务器和客户端的关系。
然而,我不知道分布式程序(例如,视频游戏)如何不仅能找到主机计算机,而且还能找到服务器正在运行的端口号,以便在两者之间创建Socket电脑。我真正看到创建Socket的唯一方法是使用已知的IP地址和已知的端口号。

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.

如何在LAN网络中搜索另一台计算机(主机)搜索客户端?

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

如何确定服务器所在的端口,而不'ping'所有可用端口的响应(我知道,坏的形式...关于服务器攻击的...)

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.

非常感谢,

Jonathan

推荐答案

它们使用的给定端口号或端口号范围(HTTP使用80,SSH使用22等)。此外,他们可以连接到主服务器,以便宣布他们的存在并了解其他节点(例如,Battle.net)。

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

如果使用Zeroconf(通过Bonjour,Avahi等)需要。 Zeroconf允许机器在LAN上执行多播DNS,而不是传统上用于DNS的点播机制。这允许他们通过网络发现也支持mDNS的机器,并发现在它们上运行的服务。

Neither of these is strictly needed if Zeroconf is used (via Bonjour, Ava 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.

这篇关于客户端如何找到服务器的端口号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆