我已经构建了一个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但无法连接的设备。 任何帮助非常感谢
答案 0 :(得分:0)
我不知道这会有多大帮助,但这听起来像是一个网络问题。如果它刚刚停止工作并且没有任何改变代码的话,我会开始在那里进行调查。
我有一个像我这样的服务器的问题,问题最终是端口转发表搞砸了所以我试图连接到错误的机器。我刚刚修好了转发,并且责备了!一切都很好。
我希望你的问题很容易解决。