Each client is using a System.Net.Sockets.TcpClient, you will need to read its stream continouesly to find whenever something is incoming.
VB Code:
Private client As Net.Sockets.TcpClient Private readBuffer(255) As Byte Private Sub Button1_Click(...) client = New Net.Sockets.TcpClient("somewhere", 0) client.GetStream.BeginRead(readBuffer, 0, 255, AddressOf DoRead, Nothing) End Sub
And then you will need a subroutine just like on the server:
VB Code:
Private Sub DoRead(ByVal ar As IAsyncResult) Try 'EndRead returns the number of bytes that were recieved, so we will need to check so that something was recieved Dim TotalBytes As Integer = client.GetStream.EndRead(ar) If TotalBytes > 0 Dim strMessage As String = System.Text.Encoding.ASCII.GetString(readBuffer, 0, TotalBytes) 'Here is the place to do whatever you want with the incoming message: strMessage 'Calling this method again is important, it begins the read again. client.GetStream.BeginRead(readBuffer, 0, 255, AddressOf DoRead, Nothing) Catch e As Exception MessageBox.Show(e.Message) End Try End Sub




Reply With Quote