Commit 97a1b683 authored by 黄卓然's avatar 黄卓然

add MainSums的socket

parent dbfda5e8
'use strict'; 'use strict';
var ws = require('nodejs-websocket')
module.exports = function (Mainsum) {
module.exports = function(Mainsum) { }
var has = false
function broadcast (server, msg) {
server.connections.forEach(function (conn) {
has = true
conn.sendText(JSON.stringify(msg))
})
}
var timer;
var num = 0
var server = ws.createServer(function (conn) {
conn.on('text', function (result) {
if (!has) {
num = parseInt(result)
}
if (timer) {
clearInterval(timer)
}
}; timer = setInterval(function () {
num = num + Math.floor(Math.random() * (295 - 285 + 1) + 285)
broadcast(server, num)
}, 3000)
})
conn.on('error', function (code) {
console.log('异常关闭', code)
})
conn.on('close', function (code, reason) {
console.log('Connection closed')
})
}).listen(5000)
\ No newline at end of file
...@@ -2009,6 +2009,11 @@ ...@@ -2009,6 +2009,11 @@
"resolved": "https://registry.npmjs.org/nocache/-/nocache-2.1.0.tgz", "resolved": "https://registry.npmjs.org/nocache/-/nocache-2.1.0.tgz",
"integrity": "sha512-0L9FvHG3nfnnmaEQPjT9xhfN4ISk0A8/2j4M37Np4mcDesJjHgEUfgPhdCyZuFI954tjokaIj/A3NdpFNdEh4Q==" "integrity": "sha512-0L9FvHG3nfnnmaEQPjT9xhfN4ISk0A8/2j4M37Np4mcDesJjHgEUfgPhdCyZuFI954tjokaIj/A3NdpFNdEh4Q=="
}, },
"nodejs-websocket": {
"version": "1.7.2",
"resolved": "https://registry.npmjs.org/nodejs-websocket/-/nodejs-websocket-1.7.2.tgz",
"integrity": "sha512-PFX6ypJcCNDs7obRellR0DGTebfUhw1SXGKe2zpB+Ng1DQJhdzbzx1ob+AvJCLzy2TJF4r8cCDqMQqei1CZdPQ=="
},
"nodemailer": { "nodemailer": {
"version": "4.7.0", "version": "4.7.0",
"resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-4.7.0.tgz", "resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-4.7.0.tgz",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment