jchristn/WatsonWebsocket

Listening on more than one hostname or IP address

Closed this issue · 6 comments

Hello,

I tried the following on windows 10 and ran as administrator:

server = new WatsonWsServer("127.0.0.1+host1", 8081, false);

But this does not work. Could you share an example of listening on more than one host/ip ?

Thank you very much,
Jules

Please pardon my earlier deleted comment. It was referring to a different project.

WatsonWebsocket does not support listening on more than one prefix currently. You would have to spawn an instance for each endpoint.

Hi,

Thank you. I thought as well reading the code that there was no place where you tried to split the string or handle that...
I will try to spawn 2 instances and see what I have got.

Best,
Jules

Hi @jlopvet under the hood it uses HttpListener, which is the same substrate that Watson Webserver uses. It's reasonable to assume that this project could be amended to also support multiple prefixes. I'll add it to my list to test out when I get some time, or if you want to give it a go and submit a PR, please feel free!

Hi @jchristn

Does this mean that the README.md is incorrect? it currently says:

If you want to listen on more than one hostname or IP address, use * or +. You MUST:
Run WatsonWebsocket as administrator for this to work (this is an operating system limitation)
Use the server constructor that takes distinct hostname and port values (not the URI-based constructor)

Hi @SieBRUM

Does this mean that the README.md is incorrect?

I may have misinterpreted the question, and this certainly is a way to achieve the same goal.

  1. If you want to be explicit about on which prefixes you listen, the library will need to be modified. The substrate under the library supports listening on "localhost:8000", "192.168.1.143:8000", etc, when those prefixes are discrete, but the library does not currently
  2. You absolutely can set your listener hostname to *, +, or 0.0.0.0 (OS dependent) to listen on anything. I do this all the time, just generally not in production, because it requires running as administrator.

Cheers, Joel

Just uploaded a new version containing a constructor that supports multiple listener prefixes. Please re-open if any issues!

NuGet: https://www.nuget.org/packages/WatsonWebsocket/2.3.2
Commit: 7944cfb

List<string> hostnames = new List<string>
{
  "192.168.1.163",
  "127.0.0.1"
};

WatsonWsServer server = new WatsonWsServer(hostnames, 8000, false);

Cheers, Joel