さて、私はクライアントサーバーアプリケーションを作成していて、クライアントにメッセージをうまく送信できますが、逆に(クライアントからサーバーへ)サーバーアプリケーションを閉じると、これを修正する方法について何か助けがありますか?
public void OnDataReceived(IAsyncResult asyn)
{
try
{
SocketPacket socketData = (SocketPacket)asyn.AsyncState;
int iRx = 0;
iRx = socketData.m_currentSocket.EndReceive(asyn);
char[] chars = new char[iRx + 1];
System.Text.Decoder d = System.Text.Encoding.UTF8.GetDecoder();
int charLen = d.GetChars(socketData.dataBuffer,
0, iRx, chars, 0);
System.String szData = new System.String(chars);
area1.AppendText(szData);
WaitForData(socketData.m_currentSocket); // Continue the waiting for data on the Socket
}
catch (ObjectDisposedException)
{
System.Diagnostics.Debugger.Log(0, "1", "\nOnDataReceived: Socket has been closed\n");
}
catch (SocketException se)
{
MessageBox.Show(se.Message);
}
}
いくつかのブレークポイントを実行した後、この部分に到達した後、textAreaに追加しようとすると、エラーなしで閉じることに気付きました。
これを修正する方法について何かアイデアはありますか?スレッドと関係があると思いますが、なぜ閉じるのかわかりません。