Click or drag to resize

TcpClientOpenStream Method

Opens a TCP connection.

Namespace:  Demo3D.Net.Protocols
Assembly:  Demo3D.IO (in Demo3D.IO.dll) Version: 15.0.2.11458
Syntax
C#
public static Client<IByteStreamService> OpenStream(
	string host,
	int port,
	Flags flags = default
)

Parameters

host
Type: SystemString
The host to connect to.
port
Type: SystemInt32
The port to connect to.
flags (Optional)
Type: Demo3D.NetFlags
Connection flags.

Return Value

Type: ClientIByteStreamService
A new TCP client.
Remarks
Don't use blocking methods in Demo3D scripting. Consider using OpenAsync(Boolean, String, Int32, Flags) instead.
Examples
C#
public void SendMessage(string host, int port) {
    // Open a connection to a client.
    var client = TcpClient.OpenStream(host, port);

    // Send a message.
    var message = new byte[4];
    client.IO.Stream.Write(message, 0, message.Length);

    // 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, OpenFlags.NoOpen);

    // 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