Skip to content

Added SetReuseAddress() method to WebSocketServer - #73

Merged
sta merged 2 commits into
sta:masterfrom
jhovgaard:master
Aug 28, 2014
Merged

Added SetReuseAddress() method to WebSocketServer#73
sta merged 2 commits into
sta:masterfrom
jhovgaard:master

Conversation

@jhovgaard

Copy link
Copy Markdown
Contributor

By using SetReuseAddress() before Start() you don't have to wait for TIME_WAIT to timeout. Normally you will recieve the following exception if you try to start websocket-sharp on the same port within TIME_WAIT:

[SocketException (0x2740): Only one usage of each socket address (protocol/network address/port) is normally permitted]

@sta

sta commented Aug 26, 2014

Copy link
Copy Markdown
Owner

It looks interesting.

But, isn't it better to add as a property?

...
    private bool                               _reuseAddress;
...
    /// <summary>
    /// Gets or sets a value indicating whether the server is allowed to be bound to an address
    /// that is already in use.
    /// </summary>
    /// <remarks>
    /// If you would like to resolve to wait for socket <c>TIME_WAIT</c>, you should set this
    /// property to <c>true</c>.
    /// </remarks>
    /// <value>
    /// <c>true</c> if the server is allowed to be bound to an address that is already in use;
    /// otherwise, <c>false</c>. The default value is <c>false</c>.
    /// </value>
    public bool ReuseAddress {
      get {
        return _reuseAddress;
      }

      set {
        if (!canSet ("ReuseAddress"))
          return;

        if (value ^ _reuseAddress) {
          _listener.Server.SetSocketOption (
            SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, value);

          _reuseAddress = value;
        }
      }
    }
...

Could you test the above?

@jhovgaard

Copy link
Copy Markdown
Contributor Author

I agree, better with property. It worked perfectly. Commited.

@sta

sta commented Aug 27, 2014

Copy link
Copy Markdown
Owner

I will merge this PR, and then add the following comment to that .cs file.

/*
 * Contributors:
 * - Jonas Hovgaard <j@jhovgaard.dk>
 */

Is it okay?

@jhovgaard

Copy link
Copy Markdown
Contributor Author

Yes, that's cool :-)

sta added a commit that referenced this pull request Aug 28, 2014
Added ReuseAddress property to WebSocketServer
@sta
sta merged commit 3f7e2ab into sta:master Aug 28, 2014
sta added a commit that referenced this pull request Aug 28, 2014
sta added a commit that referenced this pull request Sep 4, 2014
…lso closes the underlying Socket, and creates a new Socket for the TcpListener. If you set any properties on the underlying Socket prior to calling the Stop method, those properties will not carry over to the new Socket.'
sta added a commit that referenced this pull request Oct 20, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants