Early Preview

This is currently very much a preview. Please feel free to try things out, but don't be upset if anything is not yet working. Feedback is welcome over on our GitHub Dicussions page.

class System.​Net.​Sockets.​TcpListener

Assembly: System.Net.Sockets

Inheritance: object → TcpListener

Implemented Interfaces

Listens for connections from TCP network clients.

Properties

protected bool
Active
Gets a value that indicates whether <see cref="T:System.Net.Sockets.TcpListener" /> is actively listening for client connections.
public bool
ExclusiveAddressUse
Gets or sets a <see cref="T:System.Boolean" /> value that specifies whether the <see cref="T:System.Net.Sockets.TcpListener" /> allows only one underlying socket to listen to a specific port.
public EndPoint
LocalEndpoint
Gets the underlying <see cref="T:System.Net.EndPoint" /> of the current <see cref="T:System.Net.Sockets.TcpListener" /> .
public Socket
Server
Gets the underlying network <see cref="T:System.Net.Sockets.Socket" /> .

Methods

public Socket
AcceptSocket​()
Accepts a pending connection request.
Returns A <see cref="T:System.Net.Sockets.Socket" /> used to send and receive data.
AcceptSocketAsync​()
Accepts a pending connection request as an asynchronous operation.
Returns The task object representing the asynchronous operation. The <see cref="P:System.Threading.Tasks.Task`1.Result" /> property on the task object returns a <see cref="T:System.Net.Sockets.Socket" /> used to send and receive data.
AcceptSocketAsync​(Threading.​CancellationToken cancellationToken)
Accepts a pending connection request as a cancellable asynchronous operation.
Returns The task object representing the asynchronous operation. The <see cref="P:System.Threading.Tasks.Task`1.Result" /> property on the task object returns a <see cref="T:System.Net.Sockets.Socket" /> used to send and receive data.
cancellationToken A cancellation token that can be used to cancel the asynchronous operation.
public TcpClient
AcceptTcpClient​()
Accepts a pending connection request.
Returns A <see cref="T:System.Net.Sockets.TcpClient" /> used to send and receive data.
AcceptTcpClientAsync​()
Accepts a pending connection request as an asynchronous operation.
Returns The task object representing the asynchronous operation. The <see cref="P:System.Threading.Tasks.Task`1.Result" /> property on the task object returns a <see cref="T:System.Net.Sockets.TcpClient" /> used to send and receive data.
AcceptTcpClientAsync​(Threading.​CancellationToken cancellationToken)
Accepts a pending connection request as a cancellable asynchronous operation.
Returns The task object representing the asynchronous operation. The <see cref="P:System.Threading.Tasks.Task`1.Result" /> property on the task object returns a <see cref="T:System.Net.Sockets.TcpClient" /> used to send and receive data.
cancellationToken A cancellation token that can be used to cancel the asynchronous operation
public void
AllowNatTraversal​(bool allowed)
Enables or disables Network Address Translation (NAT) traversal on a <see cref="T:System.Net.Sockets.TcpListener" /> instance.
allowed A Boolean value that specifies whether to enable or disable NAT traversal.
public IAsyncResult
BeginAcceptSocket​(AsyncCallback callback, object state)
Begins an asynchronous operation to accept an incoming connection attempt.
Returns An <see cref="T:System.IAsyncResult" /> that references the asynchronous creation of the <see cref="T:System.Net.Sockets.Socket" /> .
callback An <see cref="T:System.AsyncCallback" /> delegate that references the method to invoke when the operation is complete.
state A user-defined object containing information about the accept operation. This object is passed to the <paramref name="callback" /> delegate when the operation is complete.
public IAsyncResult
BeginAcceptTcpClient​(AsyncCallback callback, object state)
Begins an asynchronous operation to accept an incoming connection attempt.
Returns An <see cref="T:System.IAsyncResult" /> that references the asynchronous creation of the <see cref="T:System.Net.Sockets.TcpClient" /> .
callback An <see cref="T:System.AsyncCallback" /> delegate that references the method to invoke when the operation is complete.
state A user-defined object containing information about the accept operation. This object is passed to the <paramref name="callback" /> delegate when the operation is complete.
public static TcpListener
Create​(int port)
Creates a new <see cref="T:System.Net.Sockets.TcpListener" /> instance to listen on the specified port.
Returns A new <see cref="T:System.Net.Sockets.TcpListener" /> instance to listen on the specified port.
port The port on which to listen for incoming connection attempts.
public void
Dispose​()
Releases all resources used by the current <see cref="T:System.Net.Sockets.TcpListener" /> instance.
public Socket
EndAcceptSocket​(IAsyncResult asyncResult)
Asynchronously accepts an incoming connection attempt and creates a new <see cref="T:System.Net.Sockets.Socket" /> to handle remote host communication.
Returns A <see cref="T:System.Net.Sockets.Socket" /> . The <see cref="T:System.Net.Sockets.Socket" /> used to send and receive data.
asyncResult An <see cref="T:System.IAsyncResult" /> returned by a call to the <see cref="M:System.Net.Sockets.TcpListener.BeginAcceptSocket(System.AsyncCallback,System.Object)" /> method.
public TcpClient
EndAcceptTcpClient​(IAsyncResult asyncResult)
Asynchronously accepts an incoming connection attempt and creates a new <see cref="T:System.Net.Sockets.TcpClient" /> to handle remote host communication.
Returns A <see cref="T:System.Net.Sockets.TcpClient" /> . The <see cref="T:System.Net.Sockets.TcpClient" /> used to send and receive data.
asyncResult An <see cref="T:System.IAsyncResult" /> returned by a call to the <see cref="M:System.Net.Sockets.TcpListener.BeginAcceptTcpClient(System.AsyncCallback,System.Object)" /> method.
public bool
Pending​()
Determines if there are pending connection requests.
Returns <see langword="true" /> if connections are pending; otherwise, <see langword="false" /> .
public void
Start​()
Starts listening for incoming connection requests.
public void
Start​(int backlog)
Starts listening for incoming connection requests with a maximum number of pending connection.
backlog The maximum length of the pending connections queue.
public void
Stop​()
Closes the listener.
public bool
Equals​(object obj)
Inherited from object
protected void
Finalize​()
Inherited from object
public int
GetHashCode​()
Inherited from object
public Type
GetType​()
Inherited from object
protected object
MemberwiseClone​()
Inherited from object
public string
ToString​()
Inherited from object