如何使用C#(套接字通信)检查TCP / IP端口可用性 [英] How to check TCP/IP port availability using C# (Socket Communication)

查看:123
本文介绍了如何使用C#(套接字通信)检查TCP / IP端口可用性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我创建了一个使用TCP / IP套接字通信传输文件的应用程序。现在我想在特定端口号上添加一个检查TCP / IP连接到远程服务器的功能(是否可以转让)。所以,请任何人帮助我。谢谢。

Hi everyone,
I have created a application for transferring files using TCP/IP socket communication.Now i want to add a feature that checks TCP/IP coonection to remote server on specific port number(whether its available or not for transfer).So,Kindly any one help me in this.Thanks in advance.

推荐答案

有几种方法,其中一种是ping每隔几分钟一个地址,以确保网络仍在运行。

您还可以在System.Net.NetworkInformation.NetworkInterface中使用GetIsNetworkAvailable方法。

即使是更好的解决方案,你可以使用如果NetworkChange类及其2个事件:

NetworkAvailabilityChanged

NetworkAddressChanged



来自MSDN的更多信息< a href =http://msdn.microsoft.com/en-us/library/system.net.networkinformation.networkchange.aspx>这里 [ ^ ]
There are several ways, one of them is pinging an address every few minutes to insure the network is still up.
You can also use GetIsNetworkAvailable method in System.Net.NetworkInformation.NetworkInterface.
Even a better solution which you can use if the NetworkChange class and its 2 events:
NetworkAvailabilityChanged
NetworkAddressChanged

More info fro MSDN here[^]


这篇关于如何使用C#(套接字通信)检查TCP / IP端口可用性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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