statianzo / Fleck

C# Websocket Implementation
MIT License
2.28k stars 583 forks source link

The requested address is not valid in its context #257

Closed jxri closed 5 years ago

jxri commented 5 years ago

22:46:20 - Fatal error during startup: System.Net.Sockets.SocketException (0x80004005): The requested address is not valid in its context at System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress socketAddress) at System.Net.Sockets.Socket.Bind(EndPoint localEP) at Fleck.SocketWrapper.Bind(EndPoint endPoint) at Fleck.WebSocketServer.Start(Action1 config)`

Why am I getting this? I am using Google Cloud Windows server and the issue only seems to occur with Google Cloud's servers but on other hosts it works just fine.

That occurs when it tries to establish a connection: this._webSocketServer = new WebSocketServer("wss://" + IP + ":" + Port) { Certificate = new X509Certificate2(@"cert.pfx", "password") };

But why...?

statianzo commented 5 years ago

What's the value of IP? Is it an IPv6 value when on Google Cloud? If so, it needs to be wrapped with [ and ] so it can be distinguished from the port. See RFC-2732

You could also try either of the "Any Interface" options (0.0.0.0 or [0000:0000:0000:0000:0000:0000:0000:0000]).

https://github.com/statianzo/Fleck/blob/a7cd8ec6565fd4486cbcd4f5264aaf44801c64f6/src/Fleck/WebSocketServer.cs#L65-L81

rajshrimohanks commented 4 years ago

@jxri Did you fix this issue? How did you do it?

jxri commented 4 years ago

@jxri Did you fix this issue? How did you do it?

@rajshrimohanks I did, but I honestly forgot how I fixed it. I'm pretty sure I put 0:0:0:0 as the IP and that's how it ended up working, but not 100% sure, you could try.

rajshrimohanks commented 4 years ago

Cool. Thanks. I'll see what I can do.

DiligentKarma commented 4 years ago

@rajshrimohanks , one of the reason for this issue could be the presence of defaultProxy section in the configuration file which would be routing every outgoing call via proxy address mentioned in this setting. Ensure that either there is a proxy server/service listening at the proxy address, or comment this section to stop the routing. In case the application configuration file does not have it, and this error is still there, check for the defaultProxy section in the machine.config file. machine.config should be available in folder C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config. In our case it was the defaultProxy in machine.config. The answer is posted at https://stackoverflow.com/a/61491499/623565 as well.