服务器信息传输

// send to current request socket client
socket.emit(‘message’, “this is a test”);

// sending to all clients except sender
socket.broadcast.emit(‘message’, “this is a test”);

// sending to all clients in ‘game’ room(channel) except sender
socket.broadcast.to(‘game’).emit(‘message’, ‘nice game’);

// sending to all clients, include sender
io.sockets.emit(‘message’, “this is a test”);

// sending to all clients in ‘game’ room(channel), include sender
io.sockets.in(‘game’).emit(‘message’, ‘cool game’);

// sending to individual socketid
io.sockets.socket(socketid).emit(‘message’, ‘for your eyes only’);
上述集中方式为socket.io常用的数据传输方式,

io.sockets.on(‘connection’, function (socket) {

});

回调函数的socket参数为一个 client 与服务器的连接标示,不同的 client 会有不同的连接标示。

Read More →

1.安装nodejs编译环境

yum -y install gcc make gcc-c++ openssl-devel wget
2.下载以及解压node
wget https://nodejs.org/dist/v4.4.2/node-v4.4.2.tar.gz
tar -zxvf node-v4.4.2.tar.gz
cd node-v4.4.2

3.编译以及安装
.configure
make && make install

4.查看安装的版本
node -v

会出现 v4.4.2

环境 32位centos nginx1.6 nodejs4.4.0

1.安装nodejs
2.安装nodejs的部署神器 pm2 (npm install -g pm2)[注意用root账号全局安装]
3.利用nginx部署nodejs项目【这里用的是反向代理。nginx配置如下demo】
upstream nginx.shangzh.com {
server localhost:8000;
}
server
{
listen 80;
server_name shangzh.com;

location / {
proxy_pass http://nginx.x.shangzh.com;
}

}
Read More →