See Also

Server Class  | Server Members  | Overload List

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Language

Visual Basic

C#

C++

C++/CLI

Show All

localPort
The port to listen for connections on.
See Also Languages PowerTCP SSL Sockets for .NET

Listen(Int32) Method

Dart.PowerTCP.SslSockets Namespace > Server Class > Listen Method : Listen(Int32) Method

Begin listening on the specified port using the default network interface.

[Visual Basic]
Overloads Public Sub Listen( _    ByVal localPort As Integer _ )
[C#]
public void Listen(    int localPort );
[C++]
public: void Listen(    int localPort )
[C++/CLI]
public: void Listen(    int localPort )

Parameters

localPort
The port to listen for connections on.

Exceptions

ExceptionDescription
ArgumentOutOfRangeExceptionLocal port was not within the valid range.

Remarks

This method causes the Server object to listen for passive connections on the specified port. When a client makes a connection, the Connection event is raised and a Tcp object representing the connection is added to the Connections collection.

Example

The following example demonstrates the code required to build a simple echo server.

[Visual Basic] 

Private Sub StartServer()
   ' Begin listening for connections on port 7.
   Server1.Listen(7)
End Sub

Private Sub Server1_Connection(ByVal sender As Object, ByVal e As ConnectionEventArgs) Handles Server1.Connection
   ' This event is raised on a new thread when a connection is received.
   Try
      ' Keep receiving data until connection is closed
      Do While (e.Tcp.Connected)
         ' Receive data.
         Dim seg As Segment = e.Tcp.Receive()

         ' Echo data back to client
         e.Tcp.Send(seg.ToString())
      Loop
   Catch ex As Exception
      'eat exception
   End Try
End Sub

[C#] 


private void StartServer()
{
  
// Begin listening for connections on port 7.
  
server1.Listen(7);
}

private void server1_Connection(object sender, ConnectionEventArgs e)
{
  
// This event is raised on a new thread when a connection is received.
  
try
  {
     
// Keep receiving data until connection is closed
     
while(e.Tcp.Connected)
     {
        
// Receive data.
        
Segment seg = e.Tcp.Receive();

        
// Echo data back to client.
        
e.Tcp.Send(seg.ToString());
     }
  }
  
catch(Exception ex)
  {
     
// eat any exceptions
  }
}
                

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

Server Class  | Server Members  | Overload List


Send comments on this topic.

Documentation version 1.1.2.0.

© 2008 Dart Communications.  All rights reserved.