Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Socket.io/node.js on local network?

I have two machines on the same network say at 192.168.1.2 and 192.168.1.3.

192.168.1.2 = server/dev pc

192.168.1.3 = client/browser pc

So on the server/dev pc I have a socket.io/http server running on port 82

On the client server I'm using chrome as the browser

The server is hosting a webpage like

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

This is a necessary resource required for the socket.io client. So the resource loads on my server/dev pc, but not on my client pc. So I try:

<html>
....
    <script type="text/javascript" src="http://192.168.1.2:82/socket.io/socket.io.js"></script>
....
</html>

Now it doesn't work on either pc. I know that it should be

<script src="http://<uri:port>/socket.io/socket.io.js"></script>

as it says on the socket.io github, but I want to only test on a local network.

I've also looked at

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

but I'm using socket.io 0.8.4 so the above version doesn't work.

So how can I get the socket.io resource served to the client in a local network environment? Or do you guys know of a website serving the 0.8.4 version of socket.io I could use?

Note: There are not firewall problems.

like image 318
Derek Avatar asked Sep 19 '11 01:09

Derek


People also ask

Does Socket.IO need Internet?

socket.io only works when connected to the internet #2309.

Can I use socket IO client to connect to a standard WebSocket?

Although Socket.IO indeed uses WebSocket for transport when possible, it adds additional metadata to each packet. That is why a WebSocket client will not be able to successfully connect to a Socket.IO server, and a Socket.IO client will not be able to connect to a plain WebSocket server either.

How do I run a Socket.IO in node JS?

In order to do it, you need to create an index. js file and install socket.io and express. You can use the following command: touch index. js && npm install express socket.io && npm install --save-dev nodemon .

Does Socket.IO need node JS?

It requires almost no basic prior knowledge of Node.JS or Socket.IO, so it's ideal for users of all knowledge levels.


1 Answers

Try letting socket.io connect automagically with

var socket = io.connect();

That worked for me.

like image 163
Daniel M. Avatar answered Oct 06 '22 00:10

Daniel M.