jchristn/WatsonWebsocket

Websocket URLs

AllonisDave opened this issue · 3 comments

Will this project work with Websockets with long urls like
wss://192.168.0.123:8002/api/v2/channels/samsung.remote.control?name=xyzzy

If yes, how to set up the client?

Hi @AllonisDave thanks for your question.

I've amended the server to allow you to specify a Uri on which you wish to listen, so it will work.

What I'm unable to figure out (yet) is how to get it to listen on a base URL, i.e. /test and also have it pick up incoming websocket requests to /test/foo.

I've published the update with the Uri-based constructor to NuGet: https://www.nuget.org/packages/WatsonWebsocket/2.2.0.9
And the commit (which also has updated test client and test server projects): aaf295c

I'll see what I can do to find support for accepting connections from other URLs, and if it's possible, how I pass that context into the consuming application.

WatsonWsServer server = new WatsonWsServer(new Uri("http://192.168.1.100:9000/test/"));
WatsonWsClient client = new WatsonWsClient(new Uri("http://192.168.1.100:9000/test/"));

Quick update, I just confirmed that you can start the server without specifying a URL i.e. new Uri("http://localhost:9000"), and, specify that the client connect to a specific URL i.e. new Uri("http://localhost:9000/test/") and the client will connect and be able to exchange data with the server.

You should be able to access the full URL, URL query, and headers from the ClientConnected event; the HttpListenerContext.Request object is passed inside of the event arguments.

Please let me know if this helps.

Updated the Test.Server event for ClientConnected to show how this can be done.

image

        static void ClientConnected(object sender, ClientConnectedEventArgs args) 
        {
            Console.WriteLine("Client " + args.IpPort + " connected using URL " + args.HttpRequest.RawUrl);
            _LastIpPort = args.IpPort;
        }

Closing this one out, please re-open if you feel this doesn't address the concern!