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

Run WebSocketListener as a window service #78

Open
buhoy opened this issue Jul 7, 2016 · 3 comments
Open

Run WebSocketListener as a window service #78

buhoy opened this issue Jul 7, 2016 · 3 comments
Labels

Comments

@buhoy
Copy link

buhoy commented Jul 7, 2016

The examples use Console application with the following code to start the server:
server.Start();
Console.ReadKey(true);

But once I wrap it in a Windows service Console.ReadKey is not available.
Any advice how to modify it?

Thanks

@vtortola
Copy link
Owner

vtortola commented Jul 7, 2016

Hi,

I added a new sample about using WSL as Windows Service. Let me know if you have any question.

Cheers.

@buhoy
Copy link
Author

buhoy commented Jul 12, 2016

Hi,

My base is the WebSocketEventListener sample. I prefer to use the event approach.

The following method starts the server and exits immediately.
`
protected override void OnStart(string[] args)
{
var endpoint = new IPEndPoint(IPAddress.Any, 4002);

        using (var server = new WebSocketEventListener(endpoint, new WebSocketListenerOptions()
        {
            SubProtocols = new String[] { "test" },
            PingTimeout = Timeout.InfiniteTimeSpan,
            NegotiationTimeout = TimeSpan.FromSeconds(20),
            ParallelNegotiations = 16,
            NegotiationQueueCapacity = 256,
            //TcpBacklog = 1000,
            SendBufferSize = 8192 * 2,
            BufferManager = BufferManager.CreateBufferManager((8192 * 2 + 1024) * 1000, 8192 * 2 + 1024)
        }))
        {
            server.OnConnect += (ws) => clientConnect(ws);
            server.OnDisconnect += (ws) => OnDisconnect(ws);
            //server.OnError += (ws, ex) => Console.WriteLine("Error: " + ex.Message);
            server.OnMessage += (ws, msg) => onMessage(ws, msg);
            server.Start();

            //Console.ReadKey(true);
        }
    }

`

Thanks

@vtortola
Copy link
Owner

Same thing. On the start method, create a WebSocketListener and start it, and in the stop method, dispose it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants