문제

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:

socket.io@0.8.7 ./node_modules/socket.io

├── redis@0.6.7

├── policyfile@0.0.4

└── socket.io-client@0.8.7

So how I should point to the correct js files ?

도움이 되었습니까?

해결책

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..

다른 팁

/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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top