我有一个节点应用程序,它既是套接字客户端又是服务器
它有
var frame_io = require('socket.io');
frame_io.listen(server).on('connection', function (socket) {
socket.on('join', function(data) {
//do stuff
});
});
var io = require('socket.io-client');
var socket = io.connect('http://' + host + ':' + port, {
reconnect: true
});
然后我有:
socket.on('sync', function (msg) {
//emit something to frame_io
});
在同步上我现在需要向frame_io.listener中的套接字发出一个emit,我想知道最好的方法
感谢
答案 0 :(得分:1)
试试这个:
var serverSocket;
var frame_io = require('socket.io');
frame_io.listen(server).on('connection', function (socket) {
serverSocket = socket;
socket.on('join', function(data) {
//do stuff
});
});
var io = require('socket.io-client');
var socket = io.connect('http://' + host + ':' + port, {
reconnect: true
});
socket.on('sync', function (msg) {
//emit something to frame_io
serverSocket.emit('thing');
});
只需取出传入的套接字并将其拉出并将其全局存储在文件中。