Olivine-Labs / Alchemy-Websockets

An extremely efficient C# WebSocket server.
http://AlchemyWebsockets.net
Other
309 stars 105 forks source link

Stop() doesn't work. #107

Open jpschw opened 9 years ago

jpschw commented 9 years ago

When I invoke the Stop() method on an instance of WebSocketServer, the connection stays open.

var server = new WebSocketServer(81, IPAddress.Any)
{
    ...
};
server.Start();
Thread.Sleep(1000);
server.Stop();
mokeev1995 commented 9 years ago

Yep, I confirm it. Now I'm trying to fix it. Do you have any ideas?

Because of TcpListener we need to close all connections with users, so, how to do this? Without sending command to client to break connection.

mokeev1995 commented 9 years ago

I fix it.

as here saying:

You are responsible for closing your accepted connections separately.

so, open

Classes\UserContext.cs 

and add this code to UserContext class:

        public void Disconnect()
        {
            Context.Connection.GetStream().Close();
            Context.Connection.Close();
        }

        ~UserContext()
        {
            Disconnect();
        }

And if you collect your clients with their UserContexts then you can close all connections for each user. It should help you to stop the WebSocket server