Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot run another Server instance #100

Open
xuantuan58 opened this issue Jul 3, 2014 · 3 comments
Open

Cannot run another Server instance #100

xuantuan58 opened this issue Jul 3, 2014 · 3 comments

Comments

@xuantuan58
Copy link

I have tried this project for couple days, It works great if there is only one instance of server is running. However, If runs another instance, an exception will throw
"Only one usage of each socket address (protocol/network address/port) is normally permitted".
I found that, it can fix by updating the TCPServer.cs and add a line:

_listener.Server.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);

    public virtual void Start()
    {
        if (_listener == null)
        {
            _listener = new TcpListener(_listenAddress, _port);
            _listener.Server.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
            ThreadPool.QueueUserWorkItem(Listen, null);
        }
    }

There is another problem, I don't know why but the Stop() method doesn't work at all. When server calls Stop() there is nothing happens on client side, and the registered port still holds by the server.

@steforster
Copy link

I think you cannot run two servers in parallel on one TCP port.
In Remact.Net I used the userContext.RequestPath during OnClientConnected to select one of several WebSocket-server-handlers that are addressed by the client on one TCP port.

@xuantuan58
Copy link
Author

@steforster Of course, I tried to run in different ports

@krtrego
Copy link

krtrego commented Dec 10, 2014

Late to the thread, but I just ran into this also. The problem is that even if you specify a different port, the code is internally hard coded to open an additional socket on port 843 for some type of flash cross-domain stuff.

Assuming you're not using this, just set FlashAccessPolicyEnabled = false and you won't have to modify the source code.

WebSocketServer server = new WebSocketServer(port, IPAddress.Any);
server.FlashAccessPolicyEnabled = false;

Then you can start multiple instances on different ports.

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

No branches or pull requests

3 participants