Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

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.
<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.

1 decade ago by Heartless49

No joke, with that exact code I just posted, I changed my_public_ip to localhost and it works perfectly. I have even attempted to change all of the script calls in the html file to the full address, http://my_public_ip:3000/socket.io/socket.io.js, and the same with impact.js and main.js and it still is not happy.

The only difference is that it's on localhost, >.<

1 decade ago by Heartless49

...just an clarification statement on my first post... that's not my whole index.html, lol I can post it if anyone wants to see.

1 decade ago by Heartless49

Hmm, well now things are a bit different - I found a public storage of socket.io.js to reference to, and now it still doesn't work but the io error isn't appearing...

The public reference for it is at http://cdn.socket.io/stable/socket.io.js
Just in case anyone else would like to use it, instead of their own.

Now the errors I'm getting a bit different...
Uncaught TypeError: Object #<Object> has no method 'connect' /:34
Uncaught TypeError: Cannot call method 'emit' of undefined player.js:189

The first error, on line 34, is from the same spot in index.html where it declares the socket, now instead of not liking io, it claims that io has no connect method, lol

1 decade ago by Heiko

Hi, not sure if this will help. I had same problem a while back. Unfortunately don't remember 100% how I resolved it.

As far as I recall if you are running your client on a different domain/subdomain from your server, then you can't just link to the socket.io file on the server.

Instead copy the files in dist folder of your socket io library to your client project.
the link to socket.io.min.js

Here's the relative path to the dist folder installed for my socet.io server:
node_modules\socket.io\node_modules\socket.io-client\dist

Copy that folder to you client web folder (e.g under public, if that's your root):
e.g I copied the dist folder to socket.io.client under my public folder

Then you can add the following line to include the socket.io client into you html file:
    <script type="text/javascript" src="socket.io.client/socket.io.min.js"></script>

Hope that helps.

.H

1 decade ago by Heartless49

Thats the setup that I had originally, and it still wasn't happy. It may be cuz the guides had me linking to socket.io.js not socket.io.min.js.

1 decade ago by Heiko

Hi Heartless.

Just tested this again and it works. I can use localhost or ipaddress, but if I type in invalid ip or port nr, then I get your error.

Are you sure that you can get to your ip/port ? - Maybe some ports are blocked from the outside?

PS: I used your code (just closed up the html and added canvas), I copied the dist folder from socket.io into my public webfolder and linked to that socket.io.js or socket.io.min.js files

1 decade ago by Heartless49

Thats really weird - yeah my ports are definitely open and pointing to the right internal ip. I run multiple servers from home for web sites and games of all kinds, so I've definitely got that down.

I appreciate you checking into it, I guess ill have to give it another go.

Thanks for the update, ^^

1 decade ago by Simran

Hi...
Actually I am beginner in this... working on node.js and socket.io creating peer to peer file sharing system..But for me after ''info : socket.io started" in the terminal when I run in the browser it displays "Welcome to socket.io" That's it...and nothing else...
Can anyone help me as of what to do further..........??

1 decade ago by Milos

I'm sure if you have apache and nodejs you had to set up some kind of proxy and proxy reverse in apache conf. That's why socket.io won't work, you need to tell him to call the nodejs, eg. nodejs is set up at: example.com/nodejs and apache makes it example.com:8080

i think this would help:

http://stackoverflow.com/questions/10440965/using-socket-io-with-nodejs-on-a-server-with-apache-as-a-reverse-proxy
Page 1 of 1
« first « previous next › last »