Hi,
Your server code is not OK. The OnReceive is actually OnAccept++. It continuaously accepts a new connection and therefor drops the previous accepted connection.
If you want to accept multiple connections you'll need to have one thread for accepting connections that will fire a new thread for reading the data. If you are confindent that you can do with one connection you'l need to put the while around the reading of data.
Note that a aborted connection (from the client side) will throw an exception which you might want to handle.
Hope this helps.
Cheers, AT
<added>
Odd enough the question i got from you in my mailbox is now gone; either you have solved it or you don't want to have the question lingering around. Anyway I have made a few small modifications to the code with the big note that though it may work It Is By No Means Good Code!!!!
It does lack structure and security / crash protection. So: nice to toy with but not production code. Please treat it as such.
Private Sub OnReceive()
Dim msg As String
Thread.Sleep(1000)
client = server.AcceptTcpClient()
Using stream As NetworkStream = client.GetStream()
Dim bMsg(1023) As Byte
While True
Dim i As Integer = stream.Read(bMsg, 0, bMsg.Length)
If i > 0 Then
msg = System.Text.Encoding.ASCII.GetString(bMsg)
If InvokeRequired Then
Invoke(New _Read(AddressOf Read), msg)
End If
End If
End While
End Using
End Sub
Well, it should at least help you through the night.
small note: feel free to upvote if you like what you're reading :)
Cheers, AT