I have a basic TCP/IP communication setup between Python on a Linux host and Visual Basic on a windows host. The windows host seems to work fine, as a test, I send a 0 to the Linux machine and have it respond with a 0 printed into the Visual Basic debug console. All works fine but after Visual Basic receives the response and display it successfully, it freezes the form so I can't press another button. Here's an example of the code.
Imports System.Net
Imports System.Net.Sockets
Imports System.Text
Public Class Form1
Shared Sub Main()
Dim tcpClient As New System.Net.Sockets.TcpClient()
tcpClient.Connect("192.168.60.124", 9999)
Dim networkStream As NetworkStream = tcpClient.GetStream()
If networkStream.CanWrite And networkStream.CanRead Then
' Do a simple write.
Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes("0")
networkStream.Write(sendBytes, 0, sendBytes.Length)
' Read the NetworkStream into a byte buffer.
Dim bytes(tcpClient.ReceiveBufferSize) As Byte
networkStream.Read(bytes, 0, CInt(tcpClient.ReceiveBufferSize))
' Output the data received from the host to the console.
Dim returndata As String = Encoding.ASCII.GetString(bytes)
Console.WriteLine(("Host returned: " + returndata))
tcpClient.Close()
Else
If Not networkStream.CanRead Then
Console.WriteLine("cannot not write data to this stream")
tcpClient.Close()
Else
If Not networkStream.CanWrite Then
Console.WriteLine("cannot read data from this stream")
tcpClient.Close()
End If
End If
End If
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Main()
End Sub
End Class