0
votes

I'm trying to work with Socket.io and Django in a project and when I load the socket.io script from the server

<script src="localhost:3000/socket.io/socket.io.js"></script>
<script>
  var socket = io();
</script>

I get an error because my Django project is in localhost:8000 so I dont know why the socket.io script is trying to do requests from Django when I said that the socket.io server is in port 3000.

In js console in my browser says

GET http://localhost:8000/socket.io/EIO=3&transport=polling&t=142197415699051 404 (NOT FOUND)

and that should be looking to loacalhost:3000 and not to localhost:8000

My Django log console says:

[22/Jan/2015 18:50:23] "GET /socket.io/?EIO=3&transport=polling&t=1421974222989-62 HTTP/1.1" 404 7506

Obvously because theres not a Django url to answer that request.

How can I load a socket.io server in a Django template???

1
is loacalhost a typo?Håken Lid
Yes that was a typo. Sorry but thats not the problemCris_Towi
Try localhost:3000/socket.io/socket.io.js in your browser's url bar to verify that you get the file.Håken Lid

1 Answers

0
votes

You can't specify what port a server-side application listens to from a client-side script src attribute.

You have to configure what port socket.io uses on the server-side. See this StackOverflow for an answer on how to do that.