2

Possible Duplicate:
socket.io: Failed to load resource

I have a server already running on http://localhost:4250

I have socket.io directory, which I have downloaded from the socket.io github.

and I am trying to connect to server like:

<script src="socket.io/socket.io.js"></script>

and how I connect to server:

<script>
  var socket = io.connect('http://localhost:4250');

  socket.on('connect', function (data) 
  {
    console.log(data);
    socket.emit('my other event', { my: 'data' });
  });

</script>

I am getting these errors:

NetworkError: 404 Not Found - http://localhost/socket.io/socket.io.js"

and

ReferenceError: io is not defined

I have already tried everything I know, so I don't know what to do now.

Thank you!

Community
  • 1
  • 1
Vural
  • 8,666
  • 11
  • 40
  • 57

1 Answers1

2

The Issue

  • by adding http://localhost:4250 before the rest of the source in the link tag (for socket.io) solves this problem. This is apparently due to the way the network binds ports to localhost, however I will try to find some more information on the cause;

What to change:


Making socket.io behave:

<script src="/socket.io/socket.io.js"></script>

should be change to

<script src="http://localhost:4250/socket.io/socket.io.js"></script>


Michael Zaporozhets
  • 23,588
  • 3
  • 30
  • 47