简体   繁体   English

客户端端口检测

[英]Client Side Port Detection

I have written a two separate executable file of Server and client in C. Both executable given IP/port via command line .To establish connection I give same port number to both side . 我在C中编写了一个服务器和客户端的两个单独的可执行文件。两个可执行文件都通过命令行给出了IP /端口。为了建立连接,我给两边提供了相同的端口号。

Now I want to Multi thread my Code .Right now I am specifying port number on which server should listen. 现在我想多线程我的代码。现在我正在指定服务器应该监听的端口号。 But after multi thread,Suppose 5 thread want connection on five different port number. 但是在多线程之后,假设5个线程想要连接五个不同的端口号。 How can I multi thread client so that it automatically detect the port number of required connection.or can any other dynamic technique ?? 我怎么能多线程客户端,以便它自动检测所需连接的端口号。或任何其他动态技术?

To establish connection I give same port number to both side . 为了建立连接,我向两侧提供相同的端口号。

Why? 为什么? It isn't necessary, and using a fixed client-side port can only be counterproductive. 没有必要,使用固定的客户端端口只会适得其反。

Right now I am specifying port number on which server should listen. 现在我正在指定服务器应该监听的端口号。 But after multi thread,Suppose 5 thread want connection on five different port number. 但是在多线程之后,假设5个线程想要连接五个不同的端口号。

No problem. 没问题。

How can I multi thread client so that it automatically detect the port number of required connection. 我怎样才能多线程客户端,以便它自动检测所需连接的端口号。

There is no problem here to solve. 这里没有问题需要解决。 Don't specify the client-side port number: the system will give you a free one. 不要指定客户端端口号:系统会给你一个免费的端口号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM