Skip to content

Instantly share code, notes, and snippets.

@paco-valdez
Created January 19, 2018 19:56
Show Gist options
  • Save paco-valdez/df007b6379e30baaeec46d40b5914587 to your computer and use it in GitHub Desktop.
Save paco-valdez/df007b6379e30baaeec46d40b5914587 to your computer and use it in GitHub Desktop.
Shared Sub Connect(message As [String])
Try
' Create a TcpClient.
' Note, for this client to work you need to have a TcpServer
' connected to the same address as specified by the server, port
' combination.
Dim port As Int32 = 5005
Dim client As New TcpClient("tracking.sintrafico.com", port)
' Translate the passed message into ASCII and store it as a Byte array.
Dim data As [Byte]() = System.Text.Encoding.ASCII.GetBytes(message)
' Get a client stream for reading and writing.
' Stream stream = client.GetStream();
Dim stream As NetworkStream = client.GetStream()
' Send the message to the connected TcpServer.
stream.Write(data, 0, data.Length)
Console.WriteLine("Sent: {0}", message)
' Close everything.
stream.Close()
client.Close()
Catch e As ArgumentNullException
Console.WriteLine("ArgumentNullException: {0}", e)
Catch e As SocketException
Console.WriteLine("SocketException: {0}", e)
End Try
Console.WriteLine(ControlChars.Cr + " Press Enter to continue...")
Console.Read()
End Sub 'Connect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment