客户端如何无法找到服务器的端口号? [英] how the client(s) cant find out the port no of the server ?

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

问题描述

嗨 我已经实现了在我的计算机上运行的客户端服务器应用程序.我使用固定端口号.目前,但是我想使用server.sin_port = htons(0),它提供了一个免费的端口号.

我需要客户端无法找到端口号的帮助.服务器的?

谢谢
Merh

Hi I have implemented a Client Server application which are running on my computer. I use a Fixed port no. for the moment but I would like to use server.sin_port=htons(0) which gives a free port no.

I need help with how the client(s) cant find out the port no. of the server?

Thanks
Merh

推荐答案

首先,htons不会为您提供有关未使用端口的任何信息.它所做的事情完全不同:
http://msdn.microsoft.com/zh-我们/library/windows/desktop/ms738557%28v=vs.85%29.aspx [ http://linux.die.net/man/3/htons [ http://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xml [您了解… .因此,无论如何,最终您仍然需要使用一些固定端口.您甚至可以使用固定端口上的特殊服务来应答客户端使用哪个端口,但是为什么呢?您可能要使用一些已知端口号,但是设计了哪些知名应用程序来提供端口信息?我不知道这样的应用.原则上讲,它可以是FTP或HTTP服务,该服务将在默认端口号上使用,并为您提供一个文件,其中包含所有应用程序的端口号的网页.但是……您有多少个应用程序?您真的要参与其中吗?也许仍然可以使用精心选择的固定端口?想一想.

—SA
First of all, htons won''t give you any information on unused port. It does something completely different:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms738557%28v=vs.85%29.aspx[^],
http://linux.die.net/man/3/htons[^].

To get this port number, you need to interrogate a set of ports to find out which port is busy. I don''t want to discuss this now, because you did not even tag your platform in your question. But first, you need to determine what set of ports you can use in principle. You should not use well-known, reserved and registered ports. There is only one authority to regulate this — IANA, so you always need to consult this page: http://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xml[^]. In the application like yours you always need to select a port from Dynamic and/or Private Ports (49152-65535).

But how do you want to inform the client side part of application about a port number to use? Think about it. To read this information you need to connect a server computer, to connect it, you need to know what port to use, well, you understand…. So, anyway, eventually you will need to use some fixed port anyway. You can even have a special service working on fixed port to answer clients what port to use, but why? You might want to use some well-know port number, but what well-known application is designed to serve-up port information? I don''t know such application. In principle, it can be, say, FTP or HTTP service which would use on a default port number and give you a file a Web page with port numbers for all your application. But… how many applications do you have? Do you really want to get into this? Maybe well-selected fixed port is still accessible? Just think about it.

—SA


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

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