http://www.cnblogs.com/Wayou/p/hichat_built_with_nodejs_socket.html
转:http://blog.fens.me/nodejs-enviroment/
curl --silent --location https://rpm.nodesource.com/setup_6.x | sudo bash -
yum -y install nodejs
yum install gcc-c++ make
yum -y install nodejs
yum install gcc-c++ make
http://socket.io/get-started/chat/
http://www.cnblogs.com/Darren_code/archive/2011/10/31/2207063.html#!comments
http://blog.fens.me/nodejs-websocket-nginx/
http://blog.csdn.net/haidaochen/article/details/7257655
http://www.cnblogs.com/EricaMIN1987_IT/p/3642709.html
香蕉派安装node.js
http://cnodejs.org/topic/54032efa9769c2e93797cd06
wget http://nodejs.org/dist/v0.10.26/node-v0.10.26-linux-arm-pi.tar.gz tar -xvzf node-v0.10.26-linux-arm-pi.tar.gz node-v0.10.26-linux-arm-pi/bin/node --version
接下来写进我们的环境变量
vi .bash_profile
在里面写入
PATH=$PATH:/home/pi/node-v0.10.26-linux-arm-pi/bin
在运行source 更新
source .bash_profile
现在我们有Node命令了
node --version
1、git clone git://github.com/joyent/node.git
2、cd node
3、./configure
4、./make && make install
5、npm install --save express@4.10.2
6、npm install --save socket.io
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>Hello world</h1>');
res.sendFile(__dirname + '/index.html');
});
//io.on('connection', function(socket){
// console.log('a user connected');
// socket.on('disconnect', function(){
// console.log('user disconnected');
//
// });
//});
//io.on('connection', function(socket){
// socket.on('chat message', function(msg){
// console.log('message: ' + msg);
// });
//});
io.on('connection', function(socket){
socket.on('chat message', function(msg){
io.emit('chat message', msg);
});
});
http.listen(3000, function(){
console.log('listening on *:3000');
});
index.html
<!doctype html>
<html>
<head>
<title>Socket.IO chat</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font: 13px Helvetica, Arial; }
form { background: #000; padding: 3px; position: fixed; bottom: 0; width: 100%; }
form input { border: 0; padding: 10px; width: 90%; margin-right: .5%; }
form button { width: 9%; background: rgb(130, 224, 255); border: none; padding: 10px; }
#messages { list-style-type: none; margin: 0; padding: 0; }
#messages li { padding: 5px 10px; }
#messages li:nth-child(odd) { background: #eee; }
</style>
</head>
<script src="https://cdn.socket.io/socket.io-1.2.0.js"></script>
<script src="http://120.26.44.201:88/js/jquery.min.js"></script>
<!--<script src="/socket.io/socket.io.js"></script>-->
<script>
var socket = io();
</script>
<body>
<ul id="messages"></ul>
<form action="">
<input id="m" autocomplete="off" /><button>Send</button>
</form>
<script>
//var socket = io();
//$('form').submit(function(){
// alert("test");
// socket.emit('chat message', $('#m').val());
// $('#m').val('');
// return false;
//});
var socket = io();
$('form').submit(function(){
socket.emit('chat message', $('#m').val());
$('#m').val('');
return false;
});
socket.on('chat message', function(msg){
$('#messages').append($('<li>').text(msg));
});
</script>
</body>
</html>