无法从传输连接读取数据

无法从传输连接读取数据

本文介绍了无法从传输连接读取数据:远程主机强行关闭了现有连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个服务器应用程序,有时,当客户端尝试连接时,我收到以下错误:

I have a server app and sometimes, when the client tries to connect, I get the following error:

注意:无法从客户端获取流或登录失败"是我在 catch 语句中添加的文本

并且它停止的行(sThread:第 96 行)是:

and the line at which it stops ( sThread : line 96 ) is :

tcpClient = (TcpClient)client;
clientStream = tcpClient.GetStream();
sr = new StreamReader(clientStream);
sw = new StreamWriter(clientStream);

// line 96:
a = sr.ReadLine();

是什么导致了这个问题?请注意,它不会一直发生

What may be causing this problem? Note that it doesn't happen all the time

推荐答案

此错误通常意味着目标计算机正在运行,但您尝试连接的服务不可用.(要么停止了、崩溃了,要么正忙于另一个请求.)

This error usually means that the target machine is running, but the service that you're trying to connect to is not available. (Either it stopped, crashed, or is busy with another request.)

英文:与机器(运行服务的远程主机/服务器/PC)的连接已建立,但由于该服务在该机器上不可用,因此机器没有知道如何处理请求.

In English:The connection to the machine (remote host/server/PC that the service runs at) was made but since the service was not available on that machine, the machine didn't know what to do with the request.

如果与机器的连接不可用,您会看到不同的错误.我忘记了它是什么,但它类似于服务无法访问"或不可用".

If the connection to the machine was not available, you'd see a different error. I forget what it is, but it's along the lines of "Service Unreachable" or "Unavailable".

编辑 - 添加

这可能是由防火墙阻塞端口引起的,但鉴于您说它是间歇性的(有时客户端尝试连接时"),这不太可能.本来我没有把它包括在内,因为我在回复之前在精神上排除了它.

It IS possible that this is being caused by a firewall blocking the port, but given that you say it's intermittent ("sometimes when the client tries to connect"), that's very unlikely. I didn't include that originally because I had ruled it out mentally before replying.

这篇关于无法从传输连接读取数据:远程主机强行关闭了现有连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 21:46