Server Property
Collapse the table of content
Expand the table of content

TcpListener.Server Property

Gets the underlying network Socket.

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

Public ReadOnly Property Server As Socket

Property Value

Type: System.Net.Sockets.Socket
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.


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 Linger Socket option is configured to time out after 10 seconds if data still remains in the network buffer after the connection is closed.

Public Shared Sub listenerOption(host As String, port As Integer)
   Dim server As IPHostEntry = Dns.Resolve(host)
   Dim ipAddress As IPAddress = server.AddressList(0)

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

   Dim lingerOption As New LingerOption(True, 10)
   listenerSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Linger, lingerOption)

   ' start listening and process connections here.
End Sub 'listenerOption

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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

Community Additions

© 2016 Microsoft