CotpServerOpenAsync Method (Boolean, String, ServiceClientAsyncIPacketIOService, Int32) |
Namespace: Demo3D.Net.Protocols
public static Task<ServerSocket> OpenAsync( bool sync, string tsap, ServiceClientAsync<IPacketIOService> serviceConnection, int port = -1 )
// Start a new server, calling ServiceConnectionAsync on every connection established. public async Task StartServerAsync(string tsap) { await CotpServer.OpenAsync(sync: false, 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); } }