I am getting an error after running a chat client/server app for a few
hours - Operation is not allowed on non-connected sockets. Once I
start up the server and all the clients(only 3 at this point), things
run smoothly for a while. The error is showing up at the server, but,
seems to be b/c the client's tcpclient is no longer listening. The
tcpclient is connected the whole time, named _client. Here is the send
from the server and client where things to be crashing:
Server Send:
Public Sub SendMessage(ByVal message As String)
Try
Dim ns As System.Net.Sockets.NetworkStream
SyncLock _client.GetStream
ns = _client.GetStream
Dim bytesToSend As Byte() =
System.Text.Encoding.ASCII.GetBytes(message)
ns.Write(bytesToSend, 0, bytesToSend.Length)
ns.Flush()
End SyncLock
Catch ex As Exception
Console.WriteLine(ex.ToString)
End Try
End Sub