Here is some C++ code I have used for this purpose before. It should be easy to convert it to C#.
private: void Send(String \*msg)
{
try
{
// Create a client
Int32 port = 30000;
String \* server = S"127.0.0.1";
TcpClient \* client = new TcpClient(server, port);
// Translate message into ASCII
Byte data\[\] = System::Text::Encoding::ASCII->GetBytes(msg->ToString());
// Get a client stream for reading and writing
NetworkStream\* stream = client->GetStream();
// Send the message to the connected client
stream->Write(data, 0, data->Length);
// Close the client
client->Close();
}
catch (Exception\* e)
{
MessageBox::Show(e->get\_Message(), "XLogoff Send Message Error");
}
}
Best, Jun