123456789101112131415161718192021222324252627282930313233 |
- const socketClient = require('./socketClient')
- const Koa = require('koa')
- const app = new Koa()
- var http = require('http');
- var server = http.createServer(app.callback());
- io = require('socket.io').listen(server);
- var protocal = require('./protocal/protocal')
- var sendProtocal = require('./protocal/sendProtocal')
- var command = require('./protocal/command')
- // 为这个socket实例添加一个"data"事件处理函数
- socketClient.on('validData', function (data) {
- var dataStrs = "";
- data.forEach(function (t) {
- dataStrs += t.toString(16);
- })
- // 第二位command位转换成对应协议名
- const protocalType = command[data[1]];
- const json = protocal[protocalType](data);
- console.log(protocalType)
- if (protocalType === undefined) {
- console.log('Uknown command')
- return;
- }
- io.sockets.emit(protocalType, json);
- });
- module.exports = server
|