开发者

In .NET how to detect if the TCP port on the server is opened and/or active?

I need to establish a TCP connection with a remote machine, but before I do that, I need to detect, if the port is in use by another application (if there is already one connection on this port). In other words I want to ensure that only one applicatio开发者_Go百科n is using the same port a time.

What is the way to do it in .NET?


What do you mean by another application? The client can connect to a remote server port and if there's nothing listening to this port TcpClient will throw an exception. So attempt to connect and catch the exception. If the server application listening on this port doesn't talk the same protocol as the client an exception will be thrown when you try to send and read the data as it won't conform. All these are exceptional cases.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜