nodejs消息服务器,NodeJS服务器之间的消息

想象一下,我有5个NodeJS服务器运行一些随机操作(例如接收数据 - 该操作意味着客户端与服务器连接) . 现在我想创建一个第6个NodeJS服务器 . 我希望5个服务器与这个新服务器连接,当新客户端与5个服务器之一连接时,他们将发送消息来告诉该故事(到第6个服务器) . 如何在NodeJS服务器之间共享消息?

我的尝试:第6个NodeJS服务器:

binaryServer = BinaryServer({ port: 9003}); //Stream de Entrada

binaryServer.on('connection', function (client) {

console.log(client.id);

client.on('stream', function (stream, meta) {

console.log(client.id +"||" +stream.id);

console.log(meta);

console.log(meta);

stream.on('data', function(data){

console.log(data);

stream.write("Recebi-----> "+data);

})

stream.on('end', function () {

console.log("end");

});

stream.on('error', function (error) {

console.log(error);

});

stream.on('pause', function () {

console.log("pause");

});

stream.on('resume', function () {

console.log("resume");

});

});

client.on('close', function(){

console.log("close: "+client.id);

});

});

5个服务器之一:

binaryclient = BinaryClient('ws://localhost:9003');

//(.....)

binaryclient.on('open', function() {

console.log("opened connection");

StreamC = binaryclient.createStream("dasda");

StreamC.write("Somethin like" + total_clients);

StreamC.on('data', function(data){

console.log(data);

});

StreamC.on('error', function (error) {

console.log(error);

});

});

使用Binarjs在NodeJS中发出此错误:"Error: Listen EADDRINUSE",带有服务器端代码 .

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值