2

I want to do handshake with server using websockets. But unnfortunately i always get errors like

WebSocket connection to 'ws://localhost:80/myserverfile.php' failed: Error during WebSocket handshake: Unexpected response code: 200`

WebSocket connection to 'ws://localhost/PHPWebSocket-Chat-master/server.php' failed: WebSocket opening handshake timed out

Can anyone show me how can i make a handshake with the server ?

I have used phpwebsockets,ratchet etc libraries

Also tried this github project but failed everytime.

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
Slim Shady
  • 1,045
  • 2
  • 12
  • 38
  • Mentioned libraries perform handshake for you. The github project you linked starts the server on port 9300 but your websocket connection string indicates you are connecting to a server on port 80. The 80 is usually reserved for HTTP server, and the error you get "unexpected 200" is indication you are not connecting to a websocket server. Make sure you're initiating websocket connection to a proper server / port. – N.B. Mar 09 '15 at 13:49
  • I changed `80` to `9300` and it works but why ? @N.B. – Slim Shady Mar 09 '15 at 13:55
  • HTTP server listens on port 80. Websocket server (the one you linked on github) listens on port 9300. You tried to talk to http server via websocket protocol and it doesn't understand that protocol, hence the error you had. You changed the port and then you talked to the appropriate server and that's it. I can't explain it better than this, you need to understand what's going on - you talk to appropriate server, using appropriate protocol over appropriate port. – N.B. Mar 09 '15 at 14:07

0 Answers0