-1
メッセージを複数回(ランダムに)送信するとTCPリスナーがクラッシュし、この例外がスローされます。ここでC#TCPリスナーがクラッシュする
例外です:
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