Table of Contents

Class TcpListener

Namespace
System.Net.Sockets
Assembly
System.Net.Sockets.TcpClient.dll

Listens for connections from TCP network clients.

public class TcpListener
Inheritance
TcpListener
Inherited Members
Extension Methods

Constructors

TcpListener(IPAddress, int)

Initializes a new instance of the TcpListener class that listens for incoming connection attempts on the specified local IP address and port number.

public TcpListener(IPAddress localaddr, int port)

Parameters

localaddr IPAddress

An IPAddress that represents the local IP address.

port int

The port on which to listen for incoming connection attempts.

TcpListener(IPEndPoint)

Initializes a new instance of the TcpListener class that listens for incoming connection attempts with the specified endpoint.

public TcpListener(IPEndPoint localEP)

Parameters

localEP IPEndPoint

An IPEndPoint that represents the local endpoint to which to bind the listener Socket.

Properties

Active

Gets a value that indicates whether TcpListener is actively listening for client connections.

protected bool Active { get; }

Property Value

bool

LocalEndpoint

Gets the underlying EndPoint of the current TcpListener.

public EndPoint LocalEndpoint { get; }

Property Value

EndPoint

Server

Gets the underlying network Socket.

public Socket Server { get; }

Property Value

Socket

Methods

AcceptSocket()

Accepts a pending connection request.

public Socket AcceptSocket()

Returns

Socket

A Socket used to send and receive data.

AcceptTcpClient()

Accepts a pending connection request.

public TcpClient AcceptTcpClient()

Returns

TcpClient

A TcpClient used to send and receive data.

Start(int)

Starts listening for incoming connection requests with a maximum number of pending connection.

public void Start(int backlog)

Parameters

backlog int

The maximum length of the pending connections queue.

Stop()

Closes the listener.

public void Stop()