Search code examples
c#websocket

How to use Fleck Websocket to listen all host address in C#?


I want to listen to all host address like ws://+:3002/, because I am currently using Cloudflare Tunnel on my Ubuntu and this is the way it works. When I am using HttpListener, it can work with the expression http://+:3001. However, when I am trying to use Fleck to do that, it will throw the following exception:

Exception thrown: 'System.UriFormatException' in System.Private.Uri.dll
An unhandled exception of type 'System.UriFormatException' occurred in System.Private.Uri.dll
Invalid URI: The hostname could not be parsed.

The sample code is here:

private const string SOCKETWEBSITE = "ws://+:3002/";
WebSocketServer server = new WebSocketServer(SOCKETWEBSITE);
server.Start(HandleSocket);

In this case, how could I let it listen to all hostname?


Solution

  • It showed me another error while I am trying to try http://127.0.0.1:11451 and http://+:11451:

    System.FormatException:“Failed to parse the IP address part of the location. Please make sure you specify a valid IP address. Use 0.0.0.0 or [::] to listen on all interfaces.”
    

    So it will work if you set the listening port to 0.0.0.0 and [::]: