我已经构建了一个 Windows 服务,它通过 tcpClient 使用 IP 和端口号连接到本地网络设备。网络设备流出数据,我收到读取。这一直适用于 MONTHS 的多个设置(始终 1 台机器-> 1 个网络设备)。
现在最近几乎所有的连接尝试都开始失败了!奇怪的是,我仍然可以通过命令提示符 ping 设备。在 putty 中,不传输任何数据。使用 netstat 我没有看到列出的任何远程地址。
在我的服务中有以下错误日志消息:
Exception by Establishing TCP/IP Connection@ServiceName System.Net.Sockets.SocketException (0x80004005): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond XXX.XXX.XXX.XX:XXXX (translated into english ;D)
at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
at System.Net.Sockets.Socket.Connect(EndPoint remoteEP)
at System.Net.Sockets.TcpClient.Connect(IPEndPoint remoteEP)
at System.Net.Sockets.TcpClient.Connect(IPAddress address, Int32 port)
这与网络有关吗?或者它与Windows更新或任何东西有关?
我最近的工作代码
public void readDevice()
{
TcpClient Client = new TcpClient();
System.Net.IPAddress ip = System.Net.IPAddress.Parse(ConfigurationManager.AppSettings["IP"]);
/*
* Establishing TCP/IP Connection
*/
try
{
// IP and Port number
log.Debug("Try Client.Connect:" + ip);
Client.Connect(ip, 5000);
}
catch (Exception ex)
{
/* Handle the socket exception.... */
//this error is thrown
log.Debug("Exception by Establishing TCP/IP Connection@ServiceName "+ ex);
}
NetworkStream MessageStream = Client.GetStream();
//Magic be here
}
我真的被卡住了,因为可以ping但无法连接的设备。非常感谢任何帮助