Click or drag to resize

TcpClientOpen Method (String, Int32, Boolean)

Opens a TCP connection.

Namespace:  Demo3D.Net.Protocols
Assembly:  Demo3D.IO (in Demo3D.IO.dll) Version: 10.0.0.0 (10.0.0.0)
Syntax
C#
public static Client<IPacketIOService> Open(
	string host,
	int port,
	bool openConnection = true
)

Parameters

host
Type: SystemString
The host to connect to.
port
Type: SystemInt32
The port to connect to.
openConnection (Optional)
Type: SystemBoolean
False to return the socket without opening the connection.

Return Value

Type: ClientIPacketIOService
A new TCP client.
Remarks
Don't use blocking methods in Demo3D scripting. Consider using OpenAsync(String, Int32, Boolean) instead.
Examples
C#
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();
}
Examples
C#
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;
}
See Also