1
votes

I am creating a nodejs+express+socket.io server.

Also I created a scaffold via yeoman for my frontend app.

The socket.io server is on port 3000 and my yeoman scaffold http server on 9000.

I have managed to retrieve the socket.io.js from the socket.io server using

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

However im having this error:

GET http://localhost:9000/socket.io/?EIO=3&transport=polling&t=1425392110184-42 404 (Not Found) 

Why is the socket.io.js polling on port 9000? Moreover, how can I change this so that it'll poll on 3000 instead?

2
remove http://localhost:3000 from the script srcashley
I highly doubt that's not the problem. If I remove that then I cannot fetch the client script from the socket.io server.Adr
You have a client side issue. Can you create your own socket connection with: var socket = new io.Socket(); socket.connect('http://127.0.0.1:3000');Aleksandar Stojadinovic
@Aleksander I have figured it out already. Thanks, man!Adr

2 Answers

0
votes

The socket.io client takes an option URL argument. If not specified, it will connect using the current document origin. This means if the HTML document's URL is http://localhost:9000, then it will connect to http://localhost:9000. Specify it when you connect:

var socket = io('http://localhost:3000');

Instead of

var socket = io();
0
votes

Okay I solved it by passing the url of the socket.io as parameter to the io() function.

var socket = io('http://localhost:3000');