Permalink
Browse files

修改例子

  • Loading branch information...
chyingp committed Jan 6, 2018
1 parent a5a4fd7 commit 3865fdff49377dfffb787675d0d71b09cb70231e
@@ -4,11 +4,18 @@
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}/http-node-server/server.js"
},
{
"type": "node",
"request": "launch",
"name": "启动程序",
"program": "${file}"
}
},
]
}
@@ -0,0 +1,8 @@
<script src="/socket.io/socket.io.js"></script>
<script>
var socket = io('http://localhost:3000');
socket.on('news', function (data) {
console.log(data);
socket.emit('my other event', { my: 'data' });
});
</script>
@@ -0,0 +1,25 @@
var app = require('http').createServer(handler)
var io = require('socket.io')(app);
var fs = require('fs');
app.listen(3000);
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.on('connection', function (socket) {
socket.emit('news', { hello: 'world' });
socket.on('my other event', function (data) {
console.log(data);
});
});

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -13,6 +13,6 @@
"compression": "^1.6.2",
"cookie-parser": "^1.4.3",
"express": "^4.15.3",
"socket.io": "^2.0.1"
"socket.io": "^2.0.4"
}
}
@@ -1,18 +1,18 @@
<!-- <script src="/socket.io/socket.io.js"></script> -->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.0.3/socket.io.js"></script>
<script>
var url = 'http://www.xunjia.com';
var socket = io(url, {
path: '/push',
query: {
user_type: 1,
mid: 1,
uid: 123,
skey: '12323'
}
});
// var url = 'http://www.xunjia.com';
// var socket = io(url, {
// path: '/push',
// query: {
// user_type: 1,
// mid: 1,
// uid: 123,
// skey: '12323'
// }
// });
// var socket = io.connect(url);
// var socket = io.connect('http://localhost:3000?skey=hello');
var socket = io.connect('http://localhost:3000');
socket.on('news', function (data) {
console.log(data);
@@ -26,13 +26,13 @@ io.on('connection', function (socket) {
// console.log(data);
// });
socket.on('disconnect', function () {
console.log('disconnect: ' + socket.id);
console.log('disconnect1: ' + socket.id);
});
});
setInterval(function () {
console.log(arr.map(socket => socket.connected).join(','));
}, 3000);
// setInterval(function () {
// console.log(arr.map(socket => socket.connected).join(','));
// }, 3000);
/*
var express = require('express');
@@ -0,0 +1,10 @@
const crypto = require('crypto');
const magic = '258EAFA5-E914-47DA-95CA-C5AB0DC85B11';
const secWebSocketKey = 'w4v7O6xFTi36lq3RNcgctw==';
let secWebSocketAccept = crypto.createHash('sha1')
.update(secWebSocketKey + magic)
.digest('base64');
console.log(secWebSocketAccept);
// Oy4NRAQ13jhfONC7bP8dTKb4PTU=

0 comments on commit 3865fdf

Please sign in to comment.