Sub Test()
Dim tcpClient As New System.Net.Sockets.TcpClient()
tcpClient.Connect("192.0.3.18", 5555)
Dim networkStream As NetworkStream = tcpClient.GetStream()
If networkStream.CanWrite And networkStream.CanRead Then
'' Do a simple write.
'Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes("Is anybody there")
'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))
Print(returnData)
Else
If Not networkStream.CanRead Then
Print("cannot not write data to this stream")
tcpClient.Close()
Else
If Not networkStream.CanWrite Then
Print("cannot read data from this stream")
tcpClient.Close()
End If
End If
End If
' pause so user can view the console output
'Console.ReadLine()
End Sub
|