tcpserver - node.js net module pings and messages not happening -
I have two nodes. Js applications that are running together on my server and I do not want to send server-side messages to them native node.js (v0.10.33) module using light net weight
I I intend the first app to send the second message. I'm listening to the console log ...
,
In the first app:
var push = ''; Var Net = Requirement ('Net'); Var server = net.createServer (function (p) {p.on ('error', function (err) {console.log (err);}); push = p; setInterval (function () {push.write (JSON ) .stringify ({'f': 'ping', 'data': 'survive'}));}, 1000);}); Server.listen (8008, function () {console.log ('listen ...')}); // A real message can be sent later in the application (this example would require a settime) push.written (JSON.stringify ({'f': 'msg', 'data': 'Hello World'}) );
In other applications I see the console log open
var net = required ('net'); Var pull = new net Socket (); Bridge.connect (8008, '127.0.0.1', function () {drag.log ('open'); drag ('data', function (_) {_ = JSON.parse (_); if (_ F === 'ping') {console.log ('!!! ping !!!');} else {console.log (.data);}}); pull.on ('error', function ( Error) {console.log ('bridge:' + error);});});
However I do not see any other activity (no ping, and later after the Open Event, Hello World) and no error.
If I do not see an event to accept data: ondata or onmessage
What is wrong? Unfortunately, I should tell that this messaging scheme is basically broken. You are using TCP.
Despite the fact that TCP sends its data to the IP packet, TCP is a packet protocol not a TCP socket is just an stream of data is thus wrong to see the
data event as a logical message . In other words, at a one end, a
socket. Written
is not the same as a singledata event on a single
data in the event Multiple messages can be just one part of a message or message.
The good news is that a problem has already been solved many times. I either recommend:
- This means for passing the JSON message on TCP.
- Using some kind of pub-all messaging solution (this option makes your app more easy to scale)
- If you know that your two apps are always If you run on the same machine, you should use the node.
Comments
Post a Comment