简体   繁体   English

如何检查客户端是否连接到TCP / IP端口

[英]how to check whether a client is connected to a tcp/ip port

I have scenario where there is a application(TCP-com PORT MAPPING SOFTWARE) which act as server and listens on port(2293) and maps to COM1. 我有一个方案,其中有一个应用程序(TCP-com PORT MAPPING SOFTWARE)充当服务器并侦听端口(2293)并映射到COM1。 There is another java application where i have to check whether any client is connected on port no(2293) and if connected do some useful thing. 还有另一个Java应用程序,在该应用程序中,我必须检查端口(2293)上是否连接了任何客户端,并且如果连接了,请执行一些有用的操作。 I have to check whether this port(2293) which that software is listening is connected( not whether it is open or accessible). 我必须检查该软件正在侦听的端口(2293)是否已连接(不是打开还是可访问)。

Is there any method to detect this situation. 有什么方法可以检测到这种情况。

Thanks in advance. 提前致谢。

If it's a windows based system you should try running "netstat" from your command prompt. 如果是基于Windows的系统,则应尝试在命令提示符下运行“ netstat”。 That should show all applications with open ports and if these ports are listening for data or not. 那应该显示所有具有开放端口的应用程序,以及这些端口是否在监听数据。

Windows run cmd Windows运行cmd

netstat -an |findstr ESTABLISHED |findstr :2293

Linux run Linux运行

netstat -an |grep ESTABLISHED |grep :2293

That functionality should be in the server. 该功能应在服务器中。 It knows all right. 它知道没事。 There is no Java API that lets you detect that condition from outside. 没有Java API可让您从外部检测到这种情况。

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

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