udp 组播两个服务,接收端运行一会后就无法继续收消息,重启以后又恢复正常几分钟。 server: const config = require(’…/config’); const logger = require(’…/handler/logger’); const dgram = require(‘dgram’); var mserver = dgram.createSocket(“udp4”);
mserver.bind(()=>{ mserver.setBroadcast(true); mserver.setMulticastTTL(128); mserver.addMembership(config.mudp.mip); });
module.exports = function (msg) {
logger.info(send event: ${msg}
);
var message = Buffer.from(msg);
mserver.send(message, 0, message.length, config.mudp.port, config.mudp.mip);
};
clinet: const logger = require(’./logger’); const config = require(’…/config’); const dgram = require(‘dgram’); var client = dgram.createSocket(‘udp4’);
exports.start = function () {
“use strict”;
client.on(‘error’, err => {
logger.error(server error:\n${err.stack}
);
server.close();
});
client.on(‘listening’, () => {
var address = client.address();
logger.debug(UDP Client listening on ${ address.address }: ${address.port }
);
client.setBroadcast(true);
client.setMulticastTTL(128);
client.addMembership(config.mudp.mip);
});
client.on('message', (message, remote) => {
logger.info(`message From:${remote.address} : ${remote.port} - ${message}`);
});
client.bind({host: config.mudp.server, port: config.mudp.port, exclusive: false});
logger.debug(`UDP Client listening `);
};
运行几分钟后,client 端就再也收不到消息了。server端其实一直在发消息,server端发送消息不算多,几百条,内容不长。自己以及调试两天多了,没有头绪。向各位请教了。