Glossary Item Box
This walk-through demonstrates how to create a simple, multi-threaded echo server with the Server component. The server will simply accept all connections, receive data, and send the data back to the client.
To create a simple echo server.
[Visual Basic, C#]
[C#] // Begin listening on port 7 (the well-known port for echo) server1.Listen(7); [Visual Basic] ' Begin listening on port 7 (the well-known port for echo) Server1.Listen(7)
[Visual Basic, C#]
[C#] private void server1_Connection(object sender, Dart.PowerTCP.SslSockets.ConnectionEventArgs e) { // The Tcp instance used to communicate with the client is // found in e.Tcp. try { // Keep receiving and echoing until the client closes the connection while (e.Tcp.Connected); // This is true until client closes the connection. { // Receive the data from the client. string s = e. Tcp.Receive ().ToString(); // Send the data back to the client e.Tcp.Send(s); } } catch (Exception ex) { // just eat any exceptions } } [Visual Basic] Private Sub Server1_Connection(ByVal sender As Object, ByVal e As Dart.PowerTCP.SslSockets.ConnectionEventArgs) Handles Server1.Connection ' The Tcp instance used to communicate with the client is ' found in e.Tcp. Try ' Keep receiving and echoing until the client closes the connection Do While (e.Tcp.Connected) ' This is true until client closes the connection. ' Receive the data from the client. Dim s As String = e. Tcp.Receive ().ToString() ' Send the data back to the client e.Tcp.Send(s) Loop Catch ex As Exception ' just eat any exceptions End Try End Sub
Send comments on this topic.
Documentation version 1.1.2.0.
© 2008 Dart Communications. All rights reserved.