-1
여러 번 메시지를 보내고 (임의의) 메시지를 보낼 때 TCP 수신기가 작동을 멈추고이 예외가 발생하면 해결 방법이 있습니까? 여기 C# TCP Listener crashing
는 예외입니다 :System.IO.IOException: Unable to read data from the transport connection: An
established connection was aborted by the software in your host machine. ---
> System.Net.Sockets.SocketException: An established connection was aborted
by the software in your host machine
at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32
size, SocketFlags socketFlags)
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32
size)
--- End of inner exception stack trace ---
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32
size)
이 (예외를 던졌다 오류 라인을 표시) 나의 TCP 수신기 코드 :
static string serverstatus = "0";
try
{
server.Start();
Byte[] bytes = new Byte[256];
String data = null;
while (true)
{
TcpClient client = server.AcceptTcpClient();
data = null;
NetworkStream stream = client.GetStream();
int i;
//THROW THE ERROR
while ((i = stream.Read(bytes, 0, bytes.Length)) > 0)
{
data = System.Text.Encoding.UTF8.GetString(bytes, 0, i);
if (data != "0" && data != serverstatus)
{
serverstatus = data;
Console.WriteLine("Current Status is: " + serverstatus);
}
data = serverstatus.ToUpper();
byte[] msg = System.Text.Encoding.ASCII.GetBytes(serverstatus);
stream.Write(msg, 0, msg.Length);
Console.WriteLine("Server Sending Back: {0}", serverstatus);
}
}
}
catch (Exception _ex)
{
Console.WriteLine(_ex.ToString());
Console.ReadKey();
}
이 질문을 보셨습니까? https://stackoverflow.com/questions/14304658/c-sharp-an-established-connection-was-aborted-by-the-software-in-your-host-machi? – Dzyann