astropanic
astropanic

Reputation: 10939

node.js socket.io client and server

I want to run the simplest demo of socket.io from http://socket.io

The server (app.js) seems to work fine.

But I have trouble with the client:

<script src="/socket.io/socket.io.js"></script>
<script>
  var socket = io.connect('http://localhost');
  socket.on('news', function (data) {
    console.log(data);
    socket.emit('my other event', { my: 'data' });
  });
</script>

Where exactly should I point tho the the first script src ?

Of course I don't have the path

/socket.io/socket.io.js

In the public folder of my webserver

My installation is as follow:

Installing node:

wget http://nodejs.org/dist/node-v0.4.12.tar.gz -P /tmp
mkdir ~/opt
cd ~/opt
tar zxvf /tmp/node-v0.4.12.tar.gz
cd node-v0.4.12
PREFIX=~/opt ./configure
make
make install
echo 'export PATH=~/opt/bin:${PATH}' >> ~/.profile
source ~/.profile

test:

which node

returns:

/home/wopi/opt/bin/node

test:

node -v

returns:

v0.4.12

Installing NodePackageManager:

curl http://npmjs.org/install.sh | sh

test:

which npm

returns:

/home/wopi/opt/bin/npm

test:

npm -v 

returns

1.0.106

npm install socket.io

returns:

[email protected] ./node_modules/socket.io

├── [email protected]

├── [email protected]

└── [email protected]

So how I should point to the correct js files ?

Upvotes: 1

Views: 2185

Answers (2)

Thingy
Thingy

Reputation: 181

/socket.io/socket.io.js is built-in to the socket.io server code. You do not have to host it on a separate server.

Upvotes: 0

alessioalex
alessioalex

Reputation: 63683

You have to point the JavaScript resource to:

your_ip:port_which_socket_io_isrunning/socket.io/socket.io.js

Example:

127.0.0.1:4000/socket.io/socket.io.js

So checkout the port on which the Socket.IO has started..

Upvotes: 4

Related Questions