TcpServerOpenAsync Method (Boolean, Int32, ServiceClientAsyncIPacketIOService) |
Namespace: Demo3D.Net.Protocols
public static Task<ServerSocket> OpenAsync( bool sync, int port, ServiceClientAsync<IPacketIOService> 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<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); } }