WebSocket连接未在客户端上打开

fkaflof6  于 2022-11-11  发布在  其他
关注(0)|答案(2)|浏览(230)

I have a problem with a WebSocket connection that does not open on the client computer.
I explain the context:

  • The Websocket server is running on a WinForm application installed on the client machine. It is accessible via the port 6060. and developed with the Nuget Fleck package. It is writed in c# like this :
X509Certificate2 certificate = new X509Certificate2(bytes, certPass);
server = new WebSocketServer("wss://0.0.0.0:6060");
server.Certificate = certificate;
server.EnabledSslProtocols = SslProtocols.Ssl3 | SslProtocols.Tls | SslProtocols.Tls11 | SslProtocols.Tls12;
  • The client WebSocket is a basic web application and sends its requests to "wss:/mywebsocket.wss:6060/"
  • A certificate is installed on the client machine to allow wss on this address. An entry is added in the hosts file to bind the domain name "mywebsocket.wss" to the address 127.0.0.1 .

This system works on many computers, but some of them have this problem.
No error message in the Websocket Server application when the client tries to open the connection. So for me, the connection doesn't have "time" to reach the server, it is stopped before.
The only thing observed in the chrome development tools is an entry like this one :

In the network tab we see an empty line like this one:

As if the websocket server was not started.
For me it is a problem of configuration of the computer which would block the connections towards the address or the port. But I could not find where it comes from.
We tried to disable antivirus completely, firewall, there is no proxy or VPN, we also disabled adblockers.
If you need more information don't hesitate to ask I will edit this post.
I will listen to all suggestions.

pkbketx9

pkbketx91#

我不知道您在客户端使用什么库来连接到WS,但在我的项目中,我们使用SignalR,并且有使用它的配置:

builder.Services.AddSingleton(sp => {
    string hubUrl = "myExampleUrl";

    return new HubConnectionBuilder()
      .WithUrl(hubUrl)
      .WithAutomaticReconnect()
      .Build();
});

.WithAutomaticReconnect()指令是解决我们的一些问题的关键。也许你可以试着在你的库中找到这样的实现?

tv6aics1

tv6aics12#

我认为第2行是错误:

server = new WebSocketServer("wss://0.0.0.0:6060");

当我使用WebSocket时,我的站点以ws://开始,而不是wws://,所以我认为第2行应该如下运行:

server = new WebSocketServer("ws://0.0.0.0:6060");

相关问题