Created
January 19, 2018 19:48
-
-
Save paco-valdez/560adb935cd314eb1f295bff65ec9742 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Connect( String^ message ) | |
{ | |
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. | |
Int32 port = 5005; | |
TcpClient^ client = gcnew TcpClient( "tracking.sintrafico.com", port ); | |
// Translate the passed message into ASCII and store it as a Byte array. | |
array<Byte>^data = Text::Encoding::ASCII->GetBytes( message ); | |
// Get a client stream for reading and writing. | |
// Stream stream = client->GetStream(); | |
NetworkStream^ stream = client->GetStream(); | |
// Send the message to the connected TcpServer. | |
stream->Write( data, 0, data->Length ); | |
Console::WriteLine( "Sent: {0}", message ); | |
// Close everything. | |
client->Close(); | |
} | |
catch ( ArgumentNullException^ e ) | |
{ | |
Console::WriteLine( "ArgumentNullException: {0}", e ); | |
} | |
catch ( SocketException^ e ) | |
{ | |
Console::WriteLine( "SocketException: {0}", e ); | |
} | |
Console::WriteLine( "\n Press Enter to continue..." ); | |
Console::Read(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment