PowerTCP Sockets for .NET

from $349.00
Available Platforms

Async Server Code Example

See all PowerTCP Sockets for .NET Samples and Code Examples

The following C# example demonstrates an Async Echo Server in a console environment. The server uses on-demand IO completion threads to handle clients.

  static void Main(string[] args)
    Server server1 = new Server();

    //Start the echo server on port 7.
    //Each client is processed on its own worker thread.
    server1.Start(new ConnectThreadStart(acceptConnection), 7, null);

    Console.WriteLine("Server started. Press <enter> to stop.");

static void acceptConnection(TcpBase connection, object state)
    //While connection is open, echo data received back to the client.
    //This function executes on a worker thread.
    byte[] buffer = new byte[1024];
        Data data = connection.Read(buffer);
        if (data != null)
            connection.Write(data.Buffer, data.Offset, data.Count);
    } while (connection.State == Dart.Sockets.ConnectionState.Connected);


To download a trial please visit the PowerTCP Sockets for .NET product page.