TcpServerOpenAsync Method (Int32, ServiceClientAsyncIByteStreamService) |
Namespace: Demo3D.Net.Protocols
public static Task<ServerSocket> OpenAsync( int port, ServiceClientAsync<IByteStreamService> serviceConnection )
// Start a new server, calling ServiceConnectionAsync on every connection established. public async Task StartServerAsync(int port) { await TcpServer.OpenAsync(sync: false, port, ServiceConnectionAsync); } // Services a client connection. async Task ServiceConnectionAsync(ServerClient<IByteStreamService> socket) { Logger.Log("Connection from " + socket.Address); var stream = socket.IO.Stream; // Simple server loops forever receiving messages and printing them to the log. for (;;) { var buffer = new byte[4]; var numBytes = await stream.ReadAsync(buffer, 0, buffer.Length); if (numBytes == 0) break; Logger.Log("Message received: " + numBytes); } }