如何确定Internet上客户端与服务器之间的通信端口号 [英] How to decide on port number between client and server communication on internet

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

问题描述

我有一个客户端应用程序,它从用户的浏览器作为Java applet运行,并通过给定的端口连接到服务器.该服务器在可公开访问的云上运行.根据我以前编写套接字代码的经验,我可以决定一个随机端口号(例如5999),并将其用于客户端服务器通信.但是,在这种情况下,客户端可以是任何用户计算机,并且可以有许多用户在访问服务器.

I have a client application which runs as a Java applet from a user's browser and connects to a server via a given port. The server is running on a publicly accessible cloud. Based on my previous experience of writing socket code , I can decide upon a random port number (say 5999) and use it for client server communication. However in this case the client can be any user machine and there can be many users accessing the server.

所以问题是如何确保我使用的端口号最不可能被客户端计算机上的任何其他服务使用.

So the question is how to ensure that I use a port number which is least likely to be used by any other service on the client's computer.

我也为此目的探索了基于Web服务的协议,但是由于我的需求确实很简单并且可以通过简单的套接字通信和自定义协议来实现,因此我没有使用它.我觉得Web服务工具和诸如SOAP,CORBA之类的东西太重了.

I have also explored webservices based protocols for this purpose but I didnt use it for the reason that my requirement is really simple and it can be fulfilled with a simple socket communication and a custom protocol. I feel webservices tools and stuff like SOAP , CORBA are too heavy weight.

推荐答案

选择不在

Choose one that is not in the Service Name and Transport Protocol Port Number Registry and hope for the best.

此外,客户端可以在同一端口上连接到许多服务器.当客户端连接时,它们将在该端使用随机端口.

Also, a client can connect to many servers on the same port. When the clients connect, they will use a random port on there end.

只有服务器需要担心使用空闲端口,而客户端则需要知道该端口是什么,否则他们将无法连接到服务器.

Only the server needs to worry about using a free port, and the clients need to know what this port is else they will not be able to connect to your server.

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

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