Page 1 of 1

Problem with node, socket.io and my server

Posted: Thu May 31, 2012 6:34 pm
by Talismar
Hi everybody,

Let me try to explain my problem:

Three day ago I decided to create a multiplayer game in html5. I downloaded nodejs, socket.io, watched the excellent tutorial from hallsofvallhalla on youtube and began to devellop a little square who moves with the arrows keys.

Now everythin works localy I mean I can open two different tab and play in multi with my litte black square :)
Yesterday I was very happy to manage this, because I already tried a few months ago but without results...

But today I decided to put my webserver online. I added few rules on my router and then my friend was able to acces to my index.html and play with the square. But..... We can't see each other, we only can play alone and I can't see the connection of my friend on the socket.io logs.

Here my configuration:

- A wamp webserver on port 8085
- Nodejs and socket.io are running on port 8000
- 2 rules to forward my external IP to mine (one by port)


My index.html is very basic I call few scripts to create and move my square and I call the socket.io.js like explained on all the tutorials.

Do you have any ideas to help me ??

It would be very great !

Many thanks in advance for your replies.

And sorry if my english is not very good (I am form Switzerland :)

Re: Problem with node, socket.io and my server

Posted: Tue Jun 05, 2012 6:36 am
by Talismar
Well... Nobody tried to use node and socket.io in "online mode" ? :|

I am so sad... I will throw my project away again because I don't see the interest to be able to play my game in local mode only ^^

Re: Problem with node, socket.io and my server

Posted: Tue Jun 05, 2012 8:19 am
by Jackolantern
Hmmm...give it a little while. We do have some Node users on here, but one of them just needs to read this topic :)

Re: Problem with node, socket.io and my server

Posted: Tue Jun 05, 2012 9:46 am
by Talismar
Otherwise what can we use to create an online multiplayer game (real time) ?

I always find topics about nodejs but there certainly are other was to do it ? no ? :geek:

Re: Problem with node, socket.io and my server

Posted: Tue Jun 05, 2012 12:28 pm
by Ark
Hi, i've got a shitty game online on a linux VPS that uses node.js and socket.io. One problem which I had was that when I closed my console after running "node app.js", was the server closed and couldn't get the sockets to connect on the server (sorry if my english is bad).

so to have the node keep running permantly use Forever.

install it

Code: Select all

npm install forever
and use it

Code: Select all

forever start app.js
not sure but I think this is linux only :/

Re: Problem with node, socket.io and my server

Posted: Tue Jun 05, 2012 12:35 pm
by Talismar
I can try but even if I didn't close the console after running the js script it doesn't work.

It strange because on my computer I am able to open two browser (using the external IP of my server) and see 2 players in the game.

Re: Problem with node, socket.io and my server

Posted: Tue Jun 05, 2012 6:54 pm
by Ark
Hmm what does the console says when there's a new player or client joins? Does the console says something like "info handshake authorized 1234215" ? and does it broadcast packets? And also what about the other client that you said he doesn't sees any other player, if he's on chrome check the javascript console, does it says something like "io is not defined"

Re: Problem with node, socket.io and my server

Posted: Wed Jun 06, 2012 7:18 am
by Chris
Talismar wrote:I can try but even if I didn't close the console after running the js script it doesn't work.

It strange because on my computer I am able to open two browser (using the external IP of my server) and see 2 players in the game.
There's a reason why it's not working, doesn't just magically decide not to. Make sure you have port forwarded both ports, 8085 and 8000. I'm guessing that because they are both running on the same box, it shouldn't be a problem that web-sockets can only be established with the same server as the initial http request.

Also if you are both on the same network, you shouldn't need to port forward.

What browser are you both using? Use developer tools to see what's going wrong with the client side end of things (f12 in most browsers).

Do some debugging in you node server using "console.log()" and see what the server is spitting out in the command prompt.

Re: Problem with node, socket.io and my server

Posted: Fri Jun 08, 2012 6:43 am
by Talismar
@Ark Nothing happens in the console when a new player try to connnect.... I need to check the JS error on chrome, that's a good idea.

@Chris I forwarded the both port but I didn't try to use the same port for web-socket and my wamp server but I heard that i could be a problem to use the same port but I am going to try tonight.

I let you know for the js errors and the port forwarding.

Thanks for the help :)

Re: Problem with node, socket.io and my server

Posted: Sat Jun 09, 2012 2:31 pm
by Talismar
Everything should be good with the ports forwarding because I can acces remotly to web-socket server and wamp server.

The js error when I open my game in another computer says: cannot load ressources...

You can try if you want I let my server online for a while: http://31.31.57.135:8085/gameProject/public/

I think the problem is thise code line: <script src="http://31.31.57.135:8000/socket.io/lib/ ... "></script>

This line is in my index.html, it call the js script to run the socket.io. I tried to change the path of this link many times and I am still don't sure if it's really the way we need to call the script.