重置远程TCP端口?可能吗? [英] Reset a remote TCP port? Is it possible?

查看:162
本文介绍了重置远程TCP端口?可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序通过TCP与多个终端进行通信(通过每个终端的预定IP地址和端口号)。

I have an application which communicates via TCP to a number of re terminals (via a predetermined IP address and port number for each terminal).

这些是工业终端,所以我无法控制他们处理TCP的方式。该应用程序设计为连续运行,远程终端将受到UPS的保护。  

These are industrial terminals so I have no control over they way they handle TCP. The application is designed to be running continuously, and the remote terminals will be protected by UPS.  

如果PC主机服务器程序关闭,它将循环通过它的内部数组  TCPClients 安全地处理所有NetworkStreams并关闭TCPClients ......这里没问题。 但是,如果PC主机服务器端发生崩溃或电源故障
,以便程序不执行TCP连接的受控关闭,则无法在重新启动时重新连接到客户端(即套接字异常: "无法建立连接,因为目标计算机主动拒绝它"
等。)。 因此,看起来客户端端口处开放并继续这样做。如果他们重新启动,一切都很好,但这不可能,或者至少非常困难,当这是从
测试台转移到现实世界时。

If the PC host server program is closed it loops through it's internal array of TCPClients to safely dispose of all the NetworkStreams and close the TCPClients... no problem here.  However, if there is a crash or a power failure at the PC host server end so that the program does not perform a controlled closure of the TCP connections, I cannot then reconnect to the clients on restart (i.e Socket Exception: "no connection could be made because the target machine actively refused it" etc.).  So, it would appear that the clients are holding the port open at their end and continue to do so. If they are rebooted everything is fine but this is not going to be possible, or at least very difficult, when this is moved from the test-bench to the real-world.

TCP或IP中是否有任何内容允许我强制远程计算机重置/释放特定端口或所有端口(请记住创建原始连接的套接字实例  ;不再存在?数据丢失是
这里不是问题,重新连接所需的时间至关重要。

Is there anything in the TCP or IP which will allow me to force a remote machine to reset/release a specific port, or all ports (bearing in mind that socket instance that created the original connection no longer exists? Data loss is not an issue here, it's the time taken to reconnect that is critical.

或者......当客户端将旧连接视为仍然打开,我可以使用相同的本地端口重新连接,并让它接听并继续相同的连接吗?如果是这样的话?

Or... As the client sees the old connection as still open, can I reconnect using the same local port and have it pick up and continue the same connection? If so how?

谢谢,戴夫

推荐答案

我认为问题不在服务器端。如果发生电源回收,服务器应该干净了。我认为循环中有另一个连接没有关闭导致问题。 尝试使用其他端口号
(10,000以上)并查看是否可以建立连接。  TCP你可以省略端口号。 当您没有指定特定的端口号时,客户端和服务器可以协商一个未使用的端口号,这可能会解决这个问题。
I don't think the problem is at the server end.  If a power recycle occured the server should come up clean.  I thinks there is another connection in the loop that didn't close that is causing the problem.  Try using a different port number (above 10,000) and see if you can make the connection.  TCP you can leave out the port numbers.  When you don't specify a particular port number the client and server can then negotiate for an unused port number which may get around this issue.


这篇关于重置远程TCP端口?可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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