1

I have been developing a live chat that uses a websocket connection. It works fine on my localhost and on http servers. However, I am trying to get it working on a secure GoDaddy server with Deluxe Linux Hosting. While the client is trying to open a websocket connection from javascript, it eventually responds with "WebSocket connection to 'wss://jhaubrich.com/new.projecthandle.io/Demo/include/projectChat/php-socket.php?username=Justin' failed: Error during WebSocket handshake: Unexpected response code: 504"

A 504 Gateway Timeout Error indicates an issue with the gateway or proxy server.

If I try to open the connection again without killing the PID for the lsphp, the error written to error_log by the php-socket.php file reads "PHP Warning: socket_bind(): unable to bind address [98]: Address already in use in /home/fq2cvob2t06k/public_html/new.projecthandle.io/Demo/include/projectChat/php-socket.php on line 12"

For the socket_bind() in php-socket.php I am using port 8090.

I have tried changing ports. I have tried adding 'websocket' to the end of the url in the websocket js.

//my js to initiate the websocket var websocket = new WebSocket("ws://jhaubrich.com/new.projecthandle.io/Demo/include/projectChat/php-socket.php?username=" + userName + "" );

I expected a websocket connection to be made. Instead I get this error : "WebSocket connection to 'wss://jhaubrich.com/new.projecthandle.io/Demo/include/projectChat/php-socket.php?username=Justin' failed: Error during WebSocket handshake: Unexpected response code: 504"

jhaubrich.com
  • 79
  • 2
  • 10
  • Your connection is automatically being upgraded to use Secure Sockets - that is why the start up URL is `ws://j...` and the error is thrown from `wss://j`. You need to implement Secure Sockets. – Randy Casburn May 29 '19 at 20:00
  • Reference: https://developer.mozilla.org/en-US/docs/Web/HTTP/Protocol_upgrade_mechanism#Common_uses_for_this_mechanism – Randy Casburn May 29 '19 at 20:03
  • Okay, I changed the code to 'var websocket = new WebSocket("wss://jhaubrich.com:8090/new.projecthandle.io/Demo/include/projectChat/php-socket.php?usern ame=" + userName + "" );' – jhaubrich.com May 29 '19 at 20:15
  • The issue now is that my browser is still caching the old ProjectManagement.js code for some reason... even though I have caching disabled when the dev tools are open... – jhaubrich.com May 29 '19 at 20:16
  • When trying in Microsoft Edge I get "SCRIPT12029: SCRIPT12029: WebSocket Error: Network Error 12029, A connection with the server could not be established" – jhaubrich.com May 29 '19 at 20:30
  • I wonder if the issue might be due to the fact that I am trying to use port 8090 and GoDaddy doesn't allow custom ports. Is this something that I should contact GoDaddy support about? Doesn't seem like an issue with my code.... – jhaubrich.com May 29 '19 at 21:12

1 Answers1

1

I came to the realization that I am use a shared hosting environment. I need to purchase a Virtual Private Server where I will have root privileges. Then I will be able to use WebSockets...

jhaubrich.com
  • 79
  • 2
  • 10
  • Maybe that's not the problem. See, I'm using VPS and I'm facing the same problem as you are. Have a look at that:https://stackoverflow.com/questions/63473220/error-during-websocket-handshake-unexpected-response-code-504-nginx-and-webs and maybe we can help each other somehow. – Rogerio Brito Soares Aug 19 '20 at 12:58
  • Yes Rogerio Brito Soares, it looks like we are doing the exact same thing facing the same issue. Please let me know if you find a solution, and likewise I will let you know if I find one :) – jhaubrich.com Aug 21 '20 at 21:39
  • I believe that you should go to my repo and test it, too. Maybe we can find something together so... – Rogerio Brito Soares Aug 21 '20 at 21:41
  • I got mine working! I am using nginx to proxy the connection. I was missing the ssl directives in my nginx virtual host configuration, but once I added those I got my secure websocket to work. – jhaubrich.com Aug 25 '20 at 04:09
  • Amazing! That's great! Can you show me how you did it? Please have a little look at my question here https://stackoverflow.com/questions/63473220/error-during-websocket-handshake-unexpected-response-code-504-nginx-and-webs?noredirect=1#comment112381061_63473220 . I think it must be something related to proxy_ssl_certificate. Is that so? How did you do? – Rogerio Brito Soares Aug 25 '20 at 13:20
  • Sorry for the late reply, have you got it working yet? – jhaubrich.com Sep 10 '20 at 16:29
  • No, not yet. Unfortunately. – Rogerio Brito Soares Sep 10 '20 at 20:38