Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I get my Node/Socket.io chat to communicate when it's on a domain?
    primarykey
    data
    text
    <p>I have successfully written a very simple real-time chat out of Node JS and Socket.io. It also uses Express, Jade and Stylus - which I want to develop further.</p> <p>The current code for this is here (this works locally): <a href="https://github.com/littlejim84/basic_node_socket" rel="nofollow">https://github.com/littlejim84/basic_node_socket</a></p> <p>This is all running fine and works as expected on my local machine. Running the Node app and going to <a href="http://localhost:9000/" rel="nofollow">http://localhost:9000/</a> makes the thing work as expected. But when I put it up on my remote server, the socket wasn't connecting. I had setup Ngnix to server my Node app, something like this:</p> <pre><code>upstream basic_node_socket { server 127.0.0.1:9000; } server { listen 80; server_name example.com; location /basic_node_socket { root /var/www/example.com/basic_node_socket; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_set_header X-NginX-Proxy true; proxy_pass http://basic_node_socket/; proxy_redirect off; } } </code></pre> <p>With this I could go to the web address and it would server up my Node app, as expected, but the socket just won't connect. I'm presuming it's because on the client side now, I am listening to port 9000, which maybe has no relevance anymore now it's being served this way?</p> <p>In my client side script I have this (which does work locally):</p> <pre><code>socket = new io.Socket(null, {port: 9000}); </code></pre> <p>I'm not an expert at Node, I'm trying to wrap my head around it. Can anyone help me get this to work as expected on my remote server?</p> <p>Any help would be greatly appreciated.</p> <p><strong>UPDATE:</strong> I have seen this link which seems to detail my problem: <a href="http://community.webfaction.com/questions/3448/using-websockets-with-a-nodejs-custom-app" rel="nofollow">http://community.webfaction.com/questions/3448/using-websockets-with-a-nodejs-custom-app</a></p> <p>...this is fine and I understand I will probably need a dedicated IP so I can run Node purely on port 80 and have one of my domain names point to that IP (or I could use something like Nodestar). But I want to keep things on my own VPS. This seems good, as long as I have one Node app running. But what if I want two, or three Node JS apps running on that new dedicated IP address? That's the bit I don't understand. I've seen various vhost type setups for Node JS, but I'm not really sure how best to implement that cleanly.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload