Class ConnectionListener
TCP Listener manager with built-in events and asynchronous functionality. This networking component is typically used when writing server software.
Implements
Inherited Members
Namespace: Swan.Net
Syntax
public sealed class ConnectionListener : IDisposable
Constructors
ConnectionListener(IPAddress, Int32)
Initializes a new instance of the ConnectionListener class.
Declaration
public ConnectionListener(IPAddress listenAddress, int listenPort)
Parameters
Type | Name | Description |
---|---|---|
IPAddress | listenAddress | The listen address. |
Int32 | listenPort | The listen port. |
ConnectionListener(IPEndPoint)
Initializes a new instance of the ConnectionListener class.
Declaration
public ConnectionListener(IPEndPoint listenEndPoint)
Parameters
Type | Name | Description |
---|---|---|
IPEndPoint | listenEndPoint | The listen end point. |
ConnectionListener(Int32)
Initializes a new instance of the ConnectionListener class. It uses the loopback address for listening.
Declaration
public ConnectionListener(int listenPort)
Parameters
Type | Name | Description |
---|---|---|
Int32 | listenPort | The listen port. |
Properties
Id
Gets a unique identifier that gets automatically assigned upon instantiation of this class.
Declaration
public Guid Id { get; }
Property Value
Type | Description |
---|---|
Guid | The unique identifier. |
IsListening
Gets a value indicating whether this listener is active.
Declaration
public bool IsListening { get; }
Property Value
Type | Description |
---|---|
Boolean |
|
LocalEndPoint
Gets the local end point on which we are listening.
Declaration
public IPEndPoint LocalEndPoint { get; }
Property Value
Type | Description |
---|---|
IPEndPoint | The local end point. |
Methods
Dispose()
Declaration
public void Dispose()
Finalize()
Finalizes an instance of the ConnectionListener class.
Declaration
protected void Finalize()
Start()
Starts the listener in an asynchronous, non-blocking fashion. Subscribe to the events of this class to gain access to connected client sockets.
Declaration
public void Start()
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Cancellation has already been requested. This listener is not reusable. |
Stop()
Stops the listener from receiving new connections. This does not prevent the listener from .
Declaration
public void Stop()
ToString()
Returns a String that represents this instance.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
String | A String that represents this instance. |
Overrides
Events
OnConnectionAccepted
Occurs when a new connection is accepted.
Declaration
public event EventHandler<ConnectionAcceptedEventArgs> OnConnectionAccepted
Event Type
Type | Description |
---|---|
EventHandler<ConnectionAcceptedEventArgs> |
OnConnectionAccepting
Occurs when a new connection requests a socket from the listener. Set Cancel = true to prevent the TCP client from being accepted.
Declaration
public event EventHandler<ConnectionAcceptingEventArgs> OnConnectionAccepting
Event Type
Type | Description |
---|---|
EventHandler<ConnectionAcceptingEventArgs> |
OnConnectionFailure
Occurs when a connection fails to get accepted
Declaration
public event EventHandler<ConnectionFailureEventArgs> OnConnectionFailure
Event Type
Type | Description |
---|---|
EventHandler<ConnectionFailureEventArgs> |
OnListenerStopped
Occurs when the listener stops.
Declaration
public event EventHandler<ConnectionListenerStoppedEventArgs> OnListenerStopped
Event Type
Type | Description |
---|---|
EventHandler<ConnectionListenerStoppedEventArgs> |