1 decade ago by Heartless49
I'm really not sure how far anyone's actually gone with this whole process, and I have looked at almost every plugin, tutorial and guide that currently exists for the topic. So far I've found that the tutorials made by hallsofvallhalla works right out of the box with the fewest errors.
The only problem though, and this applies to all of the tutorials and plugins that I've tested, I cannot seem to find a solution for. Basically, the system works great when run on localhost and you join it from the same computer. However the minute I attempt to connect to that server from another computer (even one on the same network) it won't load anything and gives errors.
I've tested every plugin/tutorial's example files that they are distributed with, opened the ports on my router, disabled firewalls, and i've got it running on my Mac Server with PHP, Apache, NodeJS and Socket.IO all running perfectly. The server starts up without any errors, however when you attempt to connect to it it claims that io is not defined.
There were a LOT more errors earlier, but after some tweaking and path-changes, I was able to eliminate a few, but I'm really not sure what this problem is being caused by, since io is declared in the javascript file that is run by NodeJS when you start the server.
Using this same setup, if I change the IPs required back to localhost, and connect to it, it runs fine.
Here is my index.html - The error is being produced when it attempts to declare the socket variable.
Naturally 'my_public_ip' is my actual public ip... since I run a few web servers from home, I dont wanna give it out, lol. I'm only testing this from home to see how it would work, and so far none of the tutorials examples are able to work outside of localhost.
Here is my app.js, which is basically the javascript file that you run with NodeJS to start the actual server itself. As you can see, io is declared in the VERY beginning and since this is started before a client even attempts to connect... I really don't understand how the index.html wouldn't catch the declaration. Or how it would work locally, but not publicly.
I'm really just hoping that there's something I'm not seeing, and that the answer is so stupidly obvious, but I've already double and triple checked all my installations, versions and dependencies and gone over the code countless times.
The only problem though, and this applies to all of the tutorials and plugins that I've tested, I cannot seem to find a solution for. Basically, the system works great when run on localhost and you join it from the same computer. However the minute I attempt to connect to that server from another computer (even one on the same network) it won't load anything and gives errors.
I've tested every plugin/tutorial's example files that they are distributed with, opened the ports on my router, disabled firewalls, and i've got it running on my Mac Server with PHP, Apache, NodeJS and Socket.IO all running perfectly. The server starts up without any errors, however when you attempt to connect to it it claims that io is not defined.
There were a LOT more errors earlier, but after some tweaking and path-changes, I was able to eliminate a few, but I'm really not sure what this problem is being caused by, since io is declared in the javascript file that is run by NodeJS when you start the server.
Using this same setup, if I change the IPs required back to localhost, and connect to it, it runs fine.
Here is my index.html - The error is being produced when it attempts to declare the socket variable.
<html> <head> <title>Impact Game</title> <style type="text/css"> html,body { background-color: #000; color: #fff; font-family: helvetica, arial, sans-serif; margin: 0; padding: 0; font-size: 12pt; } #canvas { position: absolute; left: 0; right: 0; top: 0; bottom: 0; margin: auto; border: 1px solid #555; } </style> <script type="text/javascript" src="socket.io/socket.io.js"></script> <script type="text/javascript" src="lib/impact/impact.js"></script> <script type="text/javascript" src="lib/game/main.js"></script> </head> <body> <script type="text/javascript"> var namerand = Math.floor(Math.random()*999); var playername = "player" + namerand; var socket = io.connect('http://my_public_ip:3000');
Naturally 'my_public_ip' is my actual public ip... since I run a few web servers from home, I dont wanna give it out, lol. I'm only testing this from home to see how it would work, and so far none of the tutorials examples are able to work outside of localhost.
Here is my app.js, which is basically the javascript file that you run with NodeJS to start the actual server itself. As you can see, io is declared in the VERY beginning and since this is started before a client even attempts to connect... I really don't understand how the index.html wouldn't catch the declaration. Or how it would work locally, but not publicly.
var app = require('http').createServer(handler) , io = require('socket.io').listen(app) , fs = require('fs'); app.listen(3000); var playerlocation = 0; var playerlist = []; function handler (req, res) { fs.readFile(__dirname + '/index.html', function (err, data) { if (err) { res.writeHead(500); return res.end('Error loading index.html'); } res.writeHead(200); res.end(data); }); } io.sockets.on('connection', function (socket) { socket.on('recievedata', function (positionx,positiony,currentanimation,gamename) { socket.broadcast.emit('playermove', positionx,positiony,currentanimation,gamename); }); socket.on('initializeplayer', function (newplayername) { socket.clientname = newplayername; playerlist.push(newplayername); io.sockets.emit('addplayer',playerlist,newplayername); }); socket.on('disconnect', function() { delete playerlist[socket.clientname]; for(var i in playerlist) { if(playerlist[i] == socket.clientname) { playerlist.splice(i, 1); } } socket.broadcast.emit('message',socket.clientname); socket.broadcast.emit('netreplayer',playerlist); }); });
I'm really just hoping that there's something I'm not seeing, and that the answer is so stupidly obvious, but I've already double and triple checked all my installations, versions and dependencies and gone over the code countless times.