TcpClientOpen Method (String, Int32, Boolean) |
Namespace: Demo3D.Net.Protocols
public static Client<IPacketIOService> Open( string host, int port, bool openConnection = true )
public void SendMessage(string host, int port) { // Open a connection to a client. var client = TcpClient.Open(host, port); // Send a message. using (var packet = client.IO.Write()) { packet.WriteString("hello"); // The message is the string "hello". packet.Flush(); // Send the message. } // Close the connection. client.Close(); }
public Client<IPacketIOService> OpenClient(string host, int port) { // Create a connection to a client, without opening it. var client = TcpClient.Open(host, port, openConnection: false); // Get the protocol properties and set TCP.ReceiveTimeout to 1 second. dynamic properties = client.Properties; properties.TCP.ReceiveTimeout = 1000; // Open the connection. client.Open(); return client; }