I have some code what is working at the moment. But when I trie to send a message from the server to client, the client don't get it. Here is my code
VB.NET:
Dim client As Sockets.TcpClient = New Net.Sockets.TcpClient()
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
client.Connect("192.168.1.102", 3333)
sendMessage("TEST")
Dim tr As Threading.Thread
tr = New Threading.Thread(AddressOf read)
tr.Start()
End Sub
Private Sub sendMessage(ByVal text)
If client.Connected = True Then
Dim buffer() As Byte = System.Text.ASCIIEncoding.ASCII.GetBytes(Text)
client.GetStream.Write(buffer, 0, buffer.Length)
client.GetStream.Flush()
End If
End Sub
Private Sub read()
Dim listen As Boolean = True
Do While listen
Dim buffer(1000) As Byte
networkStream = client.GetStream
networkStream.Read(buffer, 0, 1000)
If Not System.Text.ASCIIEncoding.ASCII.GetString(buffer) = "" Then
MsgBox(System.Text.ASCIIEncoding.ASCII.GetString(buffer))
listen = False
client.Close()
End If
Loop
End Sub