javascript - asynchronous node.js concepts with IO -
var net = require ('net'), local_port = 8000, local_ip = '127.0.0.1', remote_port = 80, remote_ip = 'xxx.xx.xx.x', server = net.createserver (function (socket){ var servicesocket = new net.socket (); servicesocket.connect (parseint (remote_port), remote_ip, function () { socket.on ('data', function (msg){ servicesocket.write (msg); }); }); }).listen (local_port, local_ip); there server, runs code, , client, connects server , sends 2 blocks of data 1 after another, d1 , d2.
is true, d2 arrive before d1 remote_ip?
wouldn't case possible:
let's client sends d1 of size x asynchronously, , d2 of size y, y smaller x, wouldn't socket.on('data'...) fire first reception of d2 on 'data' listener?
net.createserver , net.socket both create tcp sockets.
this has few implications:
- data write first received first.
- boundaries not fixed, single
writeon 1 side may split multipledataevents on receiving side, or vise versa multiplewritecalls may become singledataevent. guarantee data remain in same order write it.
if you're interested in unordered (and unreliable) data @ node's dgram module http://nodejs.org/api/dgram.html creates udp sockets, cases want tcp.
Comments
Post a Comment