WebFaction
Community site: login faq
1
1

In the past years it has become easier to create a nodejs app and special ports for websockets are now available even for shared servers, both via https://my.webfaction.com/new-application. Combining these two however is not trivial: the 'App category' widget lets you choose between a 'Node' app and a 'Websockets app'. If your want your Node app to use websockets, you need to choose 'websockets' and then install the Node part somehow yourself, although it says that 'the custom application (read: Node) is not required to reside there (read: in the newly created Websocket app directory). Creating a Node app first, then the 'Websocket app' and using the port given from this websocket app in the Node app to listen to, does not work.

So what is the suggested way at this date (2016) to create a Node app that uses websockets, e.g. with the socket.io module?

asked 27 Apr '16, 16:13

expdesign
2338
accept rate: 0%


Creating a Node app first, then the 'Websocket app' and using the port given from this websocket app in the Node app to listen to, does not work.

Actually it does, and is the recommended way to do Node with websockets on our platform. The specific steps are:

  1. Create a Node app via the control panel - this takes care of the Node install.
  2. Create 'custom websockets app listening on port' application - this gets you the ability to do websockets.
  3. Configure your Node app to listen on the port assigned to the websockets app (by editing index.js or whatever you're using to tell your app to listen on a port).
  4. Configure your site in the control panel to use the websockets app instead of the node app. This will set up the configuration in our front-end web server so that your websocket requests will make it to your app.

If you've done that and it's not working for you, then feel free to open a support ticket to let us know the specific problem you're seeing.

Hope that helps!

permanent link

answered 27 Apr '16, 16:25

seanf
12.2k41836
accept rate: 37%

"Configure your site in the control panel to use the websockets app instead of the node app": counter-intuitive but a very important hint. Also, in case of using socket.io, the option 'path' for the io.connect function should end on /socket.io/, eg, when the website for the websocket app is subdomain '/ws', use io.connect('/',{path:'/ws/socket.io'});

(28 Apr '16, 12:00) expdesign

@seanf Correct me if I'm wrong. Right now (2019) the step n.4 is not needed. As far as I understand, the step n.2 is enough to connect the custom websocket apps port to the internet (I checked the flag "Open a port in the server firewall for the application."). This is what made my socket work.

Without the flag checked, it didn't work (even with step n.4 accomplished). Am I right? Can you shed some light on the subject?

Vito

(30 May, 07:35) tecnosoft

@tecnosoft how are you attempting to make the connection? Can you post your ws client code in a comment here?

(30 May, 14:27) seanf

@seanf Reduced to bare minimum, my code was the following:

<html>
<body>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.2.0/socket.io.dev.js"></script>
  <script>
  var socket = io.connect('http://websocketip:websocketport');
  </script>
</body>
</html>

websocketip:websocketport are IP and port obtained from "Custom websockets app (listening on port)", and it works (with firewall open checked!).

When I had a website in place (I deleted it) and no firewall open checked, I tried with each combination I could imagine (actually 4: I had 2 IPs (one for "node" and one for "Custom websockets") and 2 ports (again one for "node" and one for "Custom websockets") with no luck.

(30 May, 15:41) tecnosoft

http://websocketip:websocketport is why things seem weird for you. If you're using the websocket app type, you don't need to include the port number in your client connections.

(30 May, 15:54) seanf

@seanf Whoa! I made it more complicated than it is! You are right, I just created the new website, closed the firewall port and the connection to http://websocketip works flawlessly! Now it's clear. Many thanks!

(31 May, 07:29) tecnosoft
showing 5 of 6 show 1 more comments
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×67
×34
×27
×15
×5

question asked: 27 Apr '16, 16:13

question was seen: 3,150 times

last updated: 31 May, 07:29

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM