Skip to content

Commit 2ce90ef

Browse files
add Listener documentation
1 parent 0efd538 commit 2ce90ef

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/Listener.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,52 @@ namespace SwebSocket;
66

77
public class Listener
88
{
9+
/// <summary>
10+
/// Wether there is an incoming connection
11+
/// </summary>
912
public bool Pending => listener.Pending();
1013

1114
private TcpListener listener;
1215
private SslOptions sslOptions = SslOptions.NoSsl;
1316

17+
/// <summary>
18+
/// Create a new listener on the specified address and port.
19+
/// The listener is started immediately, see <see cref="Start"/> for more info.
20+
/// </summary>
21+
/// <param name="address"></param>
22+
/// <param name="port"></param>
1423
public Listener(IPAddress address, ushort port)
1524
{
1625
listener = new TcpListener(address, port);
1726
Start();
1827
}
1928

29+
/// <summary>
30+
/// Start the listener on the address and port specified in the constructor.
31+
/// </summary>
32+
/// <exception cref="SocketException">If the listener could not be started</exception>
2033
public void Start() => listener.Start();
34+
35+
/// <summary>
36+
/// Stop the listener.
37+
/// </summary>
38+
/// <exception cref="SocketException">If the listener could not be stopped</exception>
2139
public void Stop() => listener.Stop();
2240

41+
/// <summary>
42+
/// Use SSL for the connection. The port is left unchanged.
43+
/// </summary>
44+
/// <param name="sslOptions"></param>
2345
public Listener UseSsl(SslOptions sslOptions)
2446
{
2547
this.sslOptions = sslOptions;
2648
return this;
2749
}
2850

51+
/// <summary>
52+
/// Accept an incoming connection.
53+
/// </summary>
54+
/// <exception cref="SocketException">Listener was closed whilst waiting for an incoming Connection</exception>
2955
public WebSocket Accept()
3056
{
3157
var socket = listener.AcceptSocket();
@@ -35,6 +61,11 @@ public WebSocket Accept()
3561
return new WebSocket(connectionFrameSocket);
3662
}
3763

64+
/// <summary>
65+
/// Try to accept an incoming connection.
66+
/// </summary>
67+
/// <returns>Whether a WebSocket was accepted or not</returns>
68+
/// <exception cref="SocketException">The listener is closed</exception>
3869
public bool TryAccept(out WebSocket? webSocket)
3970
{
4071
webSocket = Pending ? Accept() : null;

0 commit comments

Comments
 (0)