CotpServerOpenAsync(String, ServiceClientAsyncIPacketIOService, Int32) Method |
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.ProtocolsAssembly: Demo3D.IO (in Demo3D.IO.dll) Version: 19.00.00
Syntaxpublic static Task<ServerSocket> OpenAsync(
string tsap,
ServiceClientAsync<IPacketIOService> serviceConnection,
int port = -1
)
Parameters
- tsap String
- The local TSAP to open the server on.
- serviceConnection ServiceClientAsyncIPacketIOService
- Delegate for servicing a new connection.
- port Int32 (Optional)
- ISO port number.
Return Value
TaskServerSocketThe COTP protocol socket.
Example
public async Task StartServerAsync(string tsap) {
await CotpServer.OpenAsync(sync: false, tsap, ServiceConnectionAsync);
}
async Task ServiceConnectionAsync(ServerClient<IPacketIOService> socket) {
Logger.Log("Connection from " + socket.Address);
for (;;) {
var buffer = await socket.IO.ReadAsync(length: -1);
string message = BinaryTextEncoding.FixedLengthASCII.GetString(buffer);
Logger.Log("Message received: " + message);
}
}
See Also