Question

So I have a small node.js and socket.io script running from a tutorial that I read, but I'm having some issues. The script seems to be working 100%. In terms of Socket.io, when I connect from the client to the server using localhost:

var socketio = io.connect("127.0.0.1:80");

It works fine, however, when I do so using my public IP address (the relevant port is open) there is a problem and it does not connect for me, however it connects for anyone who views my script. The page loads but no socket scripts take place. My console logs this:

 debug - xhr-polling writing 8::
   debug - set close timeout for client rV_r1hWJZ7gGA5ZtGCYY
   debug - xhr-polling closed due to exceeded duration
   debug - setting request GET /socket.io/1/xhr-polling/rV_r1hWJZ7gGA5ZtGCYY?t=1
399020968259
   debug - setting poll timeout
   debug - discarding transport
   debug - cleared close timeout for client rV_r1hWJZ7gGA5ZtGCYY
   debug - setting request GET /socket.io/1/jsonp-polling/rV_r1hWJZ7gGA5ZtGCYY?t
=1399020855254&i=0
   debug - setting poll timeout
   debug - discarding transport
   debug - clearing poll timeout

What might be happening here that's causing it to work for everyone except me?

Était-ce utile?

La solution

Make sure that you've included socket.io in your script tag like this:

<script type="text/javascript" src="http://yourPublicIP:port/socket.io/socket.io.js"></script>

and then you do

<script type="text/javascript">
  var socket = io.connect('http://yourPublicIP:port');
</script>
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top