Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

TcpListener.Server Property

Gets the underlying network Socket.

Namespace: System.Net.Sockets
Assembly: System (in system.dll)

public Socket Server { get; }
/** @property */
public Socket get_Server ()

public function get Server () : Socket

Property Value

The underlying Socket.

TcpListener creates a Socket to listen for incoming client connection requests. Classes deriving from TcpListener can use this property to get this Socket. Use the underlying Socket returned by the Server property if you require access beyond that which TcpListener provides.

NoteNote

The Server property only returns the Socket used to listen for incoming client connection requests. Use the AcceptSocket method to accept a pending connection request and obtain a Socket for sending and receiving data. You can also use the AcceptTcpClient method to accept a pending connection request and obtain a TcpClient for sending and receiving data.

The following code example demonstrates the use of the Server property. The underlying Socket is retrieved and the LingerSocket option is configured to time out after 10 seconds if data still remains in the network buffer after the connection is closed.

public static void listenerOption(string host, int port)
{
    IPHostEntry server = Dns.Resolve(host);
    IPAddress ipAddress = server.AddressList[0];

    Console.WriteLine("listening on {0}, port {1}", ipAddress, port);
    TcpListener listener = new TcpListener(ipAddress, port);
    Socket listenerSocket = listener.Server;        

    LingerOption lingerOption = new LingerOption(true, 10);
    listenerSocket.SetSocketOption(SocketOptionLevel.Socket, 
                      SocketOptionName.Linger, 
                      lingerOption);

    // start listening and process connections here.
    listener.Start();

}

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft