I am trying to make a program in vb net that connects to the local ip 127.0.0.1 and sends a string to port 6680, waits for a response (msgbox), sends a string again and waits for a response again (msgbox) but I can't do it, could someone help me? I want somthing like this with no classes and no methods, all in the main:
- Connection to the Local Ip (127.0.0.1)
- Send String to a port 6680 "String"
- Write the response with a msgbox
- Send String to the same port 6680 "String"
- Write the response with a msbox Thank you!
I tried this but it didn't work, it hangs:
Dim client As TcpClient = New TcpClient("127.0.0.1", port)
' Buffer to store the response bytes.
Dim data As Byte()
' String to store the response ASCII representation.
Dim responseData As String = String.Empty
' Read the first batch of the TcpServer response bytes.
Dim Stream As NetworkStream = client.GetStream()
Stream.ReadTimeout = 1000
Dim bytes As Int128 = Stream.Read(data, 0, data.Length)
responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes)
'responseData = System.Text.Encoding.GetEncoding("ISO-8859-1").GetString(data, 0, bytes);
MyData = responseData.Replace("\r\n", "")
Stream.Close()
client.Close()
MsgBox(MyData)