How to Configure WebSocket Server to Accept Secure Connection Request
NickName:habib Ask DateTime:2019-03-11T15:51:43

How to Configure WebSocket Server to Accept Secure Connection Request

Before applying ssl(I take from cloudflare) my website is loaded over http and my socket connection is made over ws and it's working fine and connection was made successfully.

conn = new WebSocket('ws://myDomain:8090');

But after applying ssl when my website loads over https the I use wss (otherwise it give error)

conn = new WebSocket('wss://myDomain:8090');

Now it gives me the error

WebSocket connection to 'wss://myDomain:8090/' failed: Error in connection establishment: net::ERR_CONNECTION_TIMED_OUT

The websocket server is started over 8090 port I also change the port to 9991 but to no avail.

Here is the code for websocket server

public function handle()
{
    $server = IoServer::factory(
        new HttpServer(
            new WsServer(
                new WebSocketController()
            )
        ),
        8090
    );
    $server->run();
}

I don't configure apache to to run a websocket server to accept secure connection request. May be due to this I am getting an error. It means that I am sending a secure connection request to an insecure websocket server. If I am right can you tell me how I configure my websocket server so that it can accept secure connection request.

I am again telling you that I am using the SSL from cloud flare. I tell me my domain and they provide me nameservers to replace it with my existing nameservers.

I requested you to give a clear solution to solve this. I am not using nginx, I am using apache on Lampp.

Copyright Notice:Content Author:「habib」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/55097326/how-to-configure-websocket-server-to-accept-secure-connection-request

Answers
habib 2019-05-19T16:02:59

Someone solved my problem. So I am posting the solution here to help others. I was making two mistakes.\n\n\nI am using SSL from cloudflare, which causes some issues. So I buy a paid SSL certificate.\nI don't configure my websocket server for wss\n\n\nSo here is the code to configure your websocket server for wss in Laravel with Ratchet\n\npublic function handle()\n{\n\n $loop = Factory::create();\n $webSock = new SecureServer(\n new Server('0.0.0.0:8090', $loop),\n $loop,\n array(\n 'local_cert' => '', // path to your cert\n 'local_pk' => '', // path to your server private key\n 'allow_self_signed' => TRUE, // Allow self signed certs (should be false \n in production)\n 'verify_peer' => FALSE\n )\n );\n // Ratchet magic\n $webServer = new IoServer(\n new HttpServer(\n new WsServer(\n new WebSocketController()\n )\n ),\n $webSock\n );\n $loop->run();\n\n}\n",


More about “How to Configure WebSocket Server to Accept Secure Connection Request” related questions

How to Configure WebSocket Server to Accept Secure Connection Request

Before applying ssl(I take from cloudflare) my website is loaded over http and my socket connection is made over ws and it's working fine and connection was made successfully. conn = new WebSock...

Show Detail

Use Secure Websocket with PHP - Crypted handshake

I read that (secure) Websocket are using the same ports that the HTTP(S) protocol. However, my PHP Websocket Server receive crypted handshake from clients, i'm listening to open connections on 1234...

Show Detail

How can I force a secure websocket connection with vapor swift?

I have a websocket server set up with vapor swift. Now I want to force the connection to use the websocket secure protocol from the server side. It's not enough to use a URL like wss://url:8080 bec...

Show Detail

How to accept secure websocket connections in HornetQ

I'm trying to configure HornetQ to accept secure websocket connections (wss://) for STOMP communications. I'm using HornetQ 2.4.0.Final. I've been successful in configuring an unsecured connection ...

Show Detail

How to configure Websocket secure (wss) on a Nginx node server?

I tried to configure a Websocket proxy on my Nginx server, but unfortunately, I don't get it working. I have read various forms but cannot get out of it. I think it has something to do between the ...

Show Detail

How to send sec-websocket-accept key for Socket.io websocket in NodeJS

I try to setup an Socket IO connection between Client and Server in NodeJs. The connection is working with "Transports: Polling" but not for "Transports: Websocket". Client sid...

Show Detail

Secure WebSocket (wss://) doesn't work on Firefox

I have a working WebSocket non secure application. But my website uses https and I need a Secure WebSocket connection to avoid Firefox to complain about the fact that the connection is insecure. I...

Show Detail

websocket secure connection wss://localhost:443/ not making a connection to server

I have a client server application, but when I try to make a WSS connection, it gives me an error. static void Main(string[] args) { Connect("wss://localhost:8080/

Show Detail

How to migrate websocket server to wss (websocket secure)?

I have to build a client-server application that uses websocket secure for communication between the parties. In order to build it, I used this repo as a skeleton: https://github.com/radu-matei/web...

Show Detail

How to debug Safari silently failing to connect to a secure WebSocket

When doing new WebSocket('ws://server/'); Safari connects fine, but when using new WebSocket('wss://server/'); it completely fails (returns a null object). Worse, it fails silently - no errors in

Show Detail