0

Can anyone tell me how to get the websocket url for site?

My site is https://example.com. I have got websocket installed by my hosting provider. But when creating a new connection via websocket url. What will be the url?

Currently I have tried following:-

socket = new WebSocket('wss://example.com');
socket = new WebSocket('wss://example.com:9000');
socket = new WebSocket('wss://example.com:12345/test');

None of the above works. My main objective is to get websocket working so that continuous ajax calls are not made in chat script I am creating in php. Thank you all!!

  • All sockets are fine. But at times you need to tell hosting provider to disable firewall in case of https (SSL) enabled domains. Hope it helps to anybody who is stuck with ports. Thank you! – Rahul Chauhan Dec 29 '15 at 06:42

1 Answers1

1

Which service is providing your websocket backend? To use websockets you would need to have a listener running. Regardless of which listener you're using it will always run on a certain port, this is the port your script should connect to.

Have a look at this answer for example: https://stackoverflow.com/a/27233865/429719 Or take a look at the documentation for these libraries: http://socketo.me/ and http://elephant.io/.

Community
  • 1
  • 1
tomvo
  • 1,409
  • 1
  • 12
  • 21
  • node_modules>websocket is installed. That probably is part of node.js. For listener I need to connect via SSH? – Rahul Chauhan Dec 22 '15 at 11:51
  • If that library is installed then you'd need to write a node script to actually use the library. Have a look here for an example: http://ahoj.io/nodejs-and-websocket-simple-chat-tutorial – tomvo Dec 22 '15 at 12:04
  • I need to first run the php file which will be running in background through command line and then it will keep on sending ajax requests? – Rahul Chauhan Dec 22 '15 at 12:52
  • if you want to use node_modules > websocket, you'd need to build a node script, as per the link I pasted in my previous comment. If you want PHP, go for any of the options in my answer. – tomvo Dec 22 '15 at 16:22