nodejs+socket.io.js
来源:互联网 发布:c语言课程设计报告 编辑:程序博客网 时间:2024/05/17 07:13
(2013-07-04 16:08:47)
转载▼
标签:
nodejs
socket.io
分类: nodejsapp.js
var app = require('http').createServer(handler)
, io = require('socket.io').listen(app)
, fs = require('fs')
app.listen(8000);
function handler (req, res) {
fs.readFile(__dirname + '/index.html',
function (err, data) {
if (err) {
res.writeHead(500);
return res.end('Error loading index.html');
}
res.writeHead(200);
res.end(data);
});
}
io.sockets.on('connection', function (socket) {
socket.emit('news', { hello: 'world' });
socket.on('my other event', function (data) {
console.log(data);
});
});
index.html
<script src="http://localhost:8000/socket.io/socket.io.js"></script>
<script>
var socket = io.connect('http://localhost:8000');
socket.on('news', function (data) {
alert(data["hello"]);
socket.emit('my other event', { my: 'data' });
});
</script>
var app = require('http').createServer(handler)
app.listen(8000);
function handler (req, res) {
}
io.sockets.on('connection', function (socket) {
});
index.html
<script src="http://localhost:8000/socket.io/socket.io.js"></script>
<script>
</script>
0 0
- nodejs+socket.io.js
- NodeJS Socket.io
- NodeJS Socket.io
- NodeJS Socket.io
- NodeJS Socket.io
- nodejs 安装 socket.io
- nodejs socket.io
- nodejs socket.io初探
- nodejs+socket.io聊天室
- nodeJS 之 socket.io
- nodejs socket.io
- nodejs socket.io 聊天室
- nodejs学习-socket.io
- nodejs socket.io
- socket.io (nodejs+express)
- nodejs--socket.io
- nodejs+socket.io初体验
- JSP+Nodejs+Socket.IO 聊天室
- poj1328 递归+区间覆盖问题
- 进制转换二
- Xcode AutoLayout 使用方向
- 安卓标签
- 看看你在Google上干了什么
- nodejs+socket.io.js
- 《数据结构》第四章 字符串和多维数组 知识结构导图——信管1133-09
- 正则表达式30分钟入门教程 作者:deerchao
- android 5分钟集成环信及时聊天DEMO
- 重载和重写的区别
- Windows下的oracle数据库的安装、卸载以及初等常见问题
- Graphics平移原点及向上向右方向为正方式变换
- Oracle数据库连接检测(Shell)
- 分治算法实现归并排序