Click or drag to resize

CotpServerOpen Method (Byte, ServiceClientAsyncIPacketIOService, Int32)

Open a COTP server. Creates a server and starts accepting connections, calling 'serviceConnection' with each connection established. This method returns after the server has been established, leaving the accepting and servicing of connections to a background thread.

Namespace:  Demo3D.Net.Protocols
Assembly:  Demo3D.IO (in Demo3D.IO.dll) Version: 15.0.2.11458
Syntax
C#
public static ServerSocket Open(
	byte[] tsap,
	ServiceClientAsync<IPacketIOService> serviceConnection,
	int port = -1
)

Parameters

tsap
Type: SystemByte
The local TSAP to open the server on.
serviceConnection
Type: Demo3D.NetServiceClientAsyncIPacketIOService
Delegate for servicing a new connection.
port (Optional)
Type: SystemInt32
ISO port number.

Return Value

Type: ServerSocket
The COTP protocol socket.
Examples
C#
// Start a new server, calling ServiceConnectionAsync on every connection established.
public void StartServer(string tsap) {
    CotpServer.Open(tsap, ServiceConnectionAsync);
}

// Services a client connection.
async Task ServiceConnectionAsync(ServerClient<IPacketIOService> socket) {
    Logger.Log("Connection from " + socket.Address);

    // Simple server loops forever receiving messages and printing them to the log.
    for (;;) {
        var    buffer  = await socket.IO.ReadAsync(length: -1);     // -1 means read all the data received
        string message = BinaryTextEncoding.FixedLengthASCII.GetString(buffer);
        Logger.Log("Message received: " + message);
    }
}
See Also