Node JS and VPS issue

For discussions about game development that does not fit in any of the other topics.
Post Reply
legoson
Posts: 7
Joined: Sun Jun 02, 2013 10:41 pm

Node JS and VPS issue

Post by legoson »

So this post follows up from my previous question about setting up a small multiplayer HTML5 game (http://indie-resource.com/forums/viewto ... =65&t=6768) following this tutorial (http://www.youtube.com/watch?v=2_e5NaDX2rs)

the problem is that these tutorials only teaches you how to create a game on localhost but I want to take it online through my website so that it becomes sort of a small online multiplayer game.

So far I have setup a VPS on dreamhost and installed Node JS on the server through SSH using putty. It seems that I can get the node (app.js) started without a problem on my VPS but the game can't seem to load on the website since I guess it has an issue with connecting with socket.io or reaching it.

On my local machine there's an index.html file that contains the line
"<script src="http://localhost:8080/socket.io/socket.io.js"></script>"
which I guess communicates with the server
then I simply run the bat file which starts app.js then everything works fine

So I changed the index file line on my website server to
"<script src="http://mywebsite.com/tutorial/socket.io ... "></script>"
but still no luck

There could be some other reason why but I think it has something to do with that line.

this is how I start the node app.js on putty

[server] $ node /home/server/mywebsite.com/tutorial/app.js

output:

info - socket.io started
warn - error raised: Error: listen EADDRINUSE



Java script console output when I try running the game off my website

Uncaught ReferenceError: require is not defined socket.io.js:12
Uncaught ReferenceError: io is not defined (mywebsite).com/:36
Uncaught TypeError: Cannot call method 'emit' of undefined
User avatar
Elvar
Posts: 86
Joined: Sun Oct 07, 2012 7:04 pm

Re: Node JS and VPS issue

Post by Elvar »

Are you sure that the port you are using, isn't in use? :)
User avatar
a_bertrand
Posts: 1536
Joined: Mon Feb 25, 2013 1:46 pm

Re: Node JS and VPS issue

Post by a_bertrand »

Depends how you installed node.js, as far I understand socket.io, it's not a real file you will find on the filesystem but it will instead have like a fixed URL for your host. No matter what directory your files are.

Try
<script src="http://mywebsite.com/socket.io/socket.io.js></script>

And tell us if that works for you or not. Also make sure you installed the socket.io module correctly ;)
Creator of Dot World Maker
Mad programmer and annoying composer
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: Node JS and VPS issue

Post by hallsofvallhalla »

You need to specify the port for node.. It does not run on 80. The port number can be found in the app.js which I assume is 8080. You need to specify that in the index file.
legoson
Posts: 7
Joined: Sun Jun 02, 2013 10:41 pm

Re: Node JS and VPS issue

Post by legoson »

I used the command npm install socket.io to install socket.io and it created a directory named "node_modules" in my root folder on the VPS. I'm not sure if I installed it incorrectly :\

the script <script src="http://mywebsite.com/socket.io/socket.io.js></script>
and
<script src="/socket.io/socket.io.js></script>

both give the get error

GET http://mywebsite.com/socket.io/socket.io.js 404 (Not Found)

also, my server app.js contains the line

app.listen(8080);
(yeah it is 8080)

and index.html contains

var socket = io.connect('http://localhost:8080');

maybe I should modify these lines too? I'm not sure what port to use on the VPS though. :|

@hallsofvallhalla how do I specify the port for node? great tutorials btw :)
User avatar
a_bertrand
Posts: 1536
Joined: Mon Feb 25, 2013 1:46 pm

Re: Node JS and VPS issue

Post by a_bertrand »

well you installed socket.io in the wrong location ;)
Just go where your server code (.js file) is, and then use the npm install command.

So if you do app.listen(8080) and you are not behind any proxy like haproxy or such, then your link should be as well loaded from the same port:
http://mywebsite.com:8080/socket.io/socket.io.js

However if you have only node.js and no apache why not run direcly on port 80? And if you have apache it would be smarter to use haproxy or equivalent and use it to split the calls based for example on the domain.
Creator of Dot World Maker
Mad programmer and annoying composer
legoson
Posts: 7
Joined: Sun Jun 02, 2013 10:41 pm

Re: Node JS and VPS issue

Post by legoson »

@a_bertrand oh did I? :lol: I'll try your suggestion after I get something to eat
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: Node JS and VPS issue

Post by hallsofvallhalla »

i am posting from my raspberry pi that is running a node server

this is my index.html
<!DOCTYPE html>
<script src="http://555.555.74.222:8081/socket.io/so ... "></script>
<html>

<head>
<title>Impact Tutorial</title>
<style type="text/css">
app.js
ar app = require('http').createServer(handler)
, io = require('socket.io').listen(app)
, fs = require('fs')


app.listen(8081);
legoson
Posts: 7
Joined: Sun Jun 02, 2013 10:41 pm

Re: Node JS and VPS issue

Post by legoson »

Sweet! I got it working! :D :D :D

Thanks for all the help guys!
Post Reply

Return to “General Development”