@@ -6,26 +6,52 @@ namespace SwebSocket;
6
6
7
7
public class Listener
8
8
{
9
+ /// <summary>
10
+ /// Wether there is an incoming connection
11
+ /// </summary>
9
12
public bool Pending => listener . Pending ( ) ;
10
13
11
14
private TcpListener listener ;
12
15
private SslOptions sslOptions = SslOptions . NoSsl ;
13
16
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>
14
23
public Listener ( IPAddress address , ushort port )
15
24
{
16
25
listener = new TcpListener ( address , port ) ;
17
26
Start ( ) ;
18
27
}
19
28
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>
20
33
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>
21
39
public void Stop ( ) => listener . Stop ( ) ;
22
40
41
+ /// <summary>
42
+ /// Use SSL for the connection. The port is left unchanged.
43
+ /// </summary>
44
+ /// <param name="sslOptions"></param>
23
45
public Listener UseSsl ( SslOptions sslOptions )
24
46
{
25
47
this . sslOptions = sslOptions ;
26
48
return this ;
27
49
}
28
50
51
+ /// <summary>
52
+ /// Accept an incoming connection.
53
+ /// </summary>
54
+ /// <exception cref="SocketException">Listener was closed whilst waiting for an incoming Connection</exception>
29
55
public WebSocket Accept ( )
30
56
{
31
57
var socket = listener . AcceptSocket ( ) ;
@@ -35,6 +61,11 @@ public WebSocket Accept()
35
61
return new WebSocket ( connectionFrameSocket ) ;
36
62
}
37
63
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>
38
69
public bool TryAccept ( out WebSocket ? webSocket )
39
70
{
40
71
webSocket = Pending ? Accept ( ) : null ;
0 commit comments