socket.io环境安装

2015-11-23

先安装node环境

wget https://nodejs.org/download/release/v0.10.40/node-v0.10.40.tar.gz --no-check-cert
tar -zxvf node-v0.10.40.tar.gz 
cd node-v0.10.40
./configure 
make
make install

出现g++错误:

yum install gcc-c++

确定是否安装OK

node -v
npm -v

vim package.json

server
{
  listen       80;
  server_name  realtime.plhwin.com;
  location / {
    proxy_pass http://127.0.0.1:3000;
  }
}

安装socket.io

npm install --save express
npm install --save socket.io

vim index.js

var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
app.get('/', function(req, res){
	res.send('<h1>Welcome Realtime Server</h1>');
});
http.listen(3000, function(){
	console.log('listening on *:3000');
});

运行

node index.js