Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion websocket-sharp/Ext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ internal static bool IsData (this Opcode opcode)

internal static bool IsPortNumber (this int value)
{
return value > 0 && value < 65536;
return value > -1 && value < 65536;
}

internal static bool IsReserved (this ushort code)
Expand Down
11 changes: 8 additions & 3 deletions websocket-sharp/Server/WebSocketServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public WebSocketServer ()
/// on which to listen.
/// </param>
/// <exception cref="ArgumentOutOfRangeException">
/// <paramref name="port"/> is less than 1 or greater than 65535.
/// <paramref name="port"/> is less than 0 or greater than 65535.
/// </exception>
public WebSocketServer (int port)
: this (port, port == 443)
Expand Down Expand Up @@ -213,12 +213,12 @@ public WebSocketServer (string url)
/// secure connections; otherwise, <c>false</c>.
/// </param>
/// <exception cref="ArgumentOutOfRangeException">
/// <paramref name="port"/> is less than 1 or greater than 65535.
/// <paramref name="port"/> is less than 0 or greater than 65535.
/// </exception>
public WebSocketServer (int port, bool secure)
{
if (!port.IsPortNumber ()) {
var msg = "Less than 1 or greater than 65535.";
var msg = "Less than 0 or greater than 65535.";
throw new ArgumentOutOfRangeException ("port", msg);
}

Expand Down Expand Up @@ -965,6 +965,11 @@ private void startReceiving ()
_receiveThread = new Thread (new ThreadStart (receiveRequest));
_receiveThread.IsBackground = true;
_receiveThread.Start ();

if (_port == 0)
{
_port = ((System.Net.IPEndPoint)_listener.LocalEndpoint).Port;
}
}

private void stop (ushort code, string reason)
Expand Down