In this case I think the data will be buffered in the kernel (outside of Node), so you don't have to worry about that too much.
On Fri, Sep 7, 2012 at 9:35 AM, Mark Volkmann <[email protected]>wrote: > I don't doubt you. I just want to see that documented somewhere or clearly > see how that is enforced in the code. I have looked at net.js. It's not the > easiest code to follow. If it's clear from that code, I could use some > pointers on where to look. > > I'll try to make my concern more clear below with very simple code for > server.js and client.js that really runs. Run "node server" in one window > and "node client" in another. > The numbered comments indicate the order in which I expect the lines to > execute. > It seems clear to me that 4 could run before 5. If that happens, how is it > that the server still gets that message? Is the message being buffered > until connListener completes? > > server.js > > var net = require('net'); > function dataListener(data) { > console.log('received', data.toString()); > } > function connListener(socket) { > socket.on('data', dataListener); // 5 > } > var server = net.createServer(connListener); // 1 > server.listen(8019); // 2 > > client.js > > var net = require('net'); > var socket = net.connect(8019); // 3 > socket.write('Is this lost?'); // 4 > > On Fri, Sep 7, 2012 at 7:29 AM, ribao wei <[email protected]> wrote: > >> It is not about node.js, it is a Javascript thing. >> >> Socket will not receive any data util it "connect". >> >> >> On Thu, Sep 6, 2012 at 11:35 PM, Hsu Ping Feng <[email protected]>wrote: >> >>> https://github.com/joyent/node/blob/master/lib/net.js >>> >>> It is a good way to understand through source code. >>> >>> >>> 2012/9/7 Mark Volkmann <[email protected]> >>> >>>> On Thu, Sep 6, 2012 at 4:40 PM, Jorge <[email protected]> wrote: >>>> >>>>> On 06/09/2012, at 23:11, Mark Volkmann wrote: >>>>> >>>> >>>> >>>>> My understanding is that node won't/shouldn't emit/dispatch any 'data' >>>>> events to the socket 'socket' until *after* having called cb(socket), 'cb' >>>>> being the callback function passed on to .createServer(cb). >>>>> >>>> >>>> I suspect you are correct. I'd like to understand how Node implements >>>> that. It would be great if this is already documented somewhere and I could >>>> just read that to understand it. >>>> >>> > -- > R. Mark Volkmann > Object Computing, Inc. > > -- > Job Board: http://jobs.nodejs.org/ > Posting guidelines: > https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines > You received this message because you are subscribed to the Google > Groups "nodejs" group. > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected] > For more options, visit this group at > http://groups.google.com/group/nodejs?hl=en?hl=en > -- Job Board: http://jobs.nodejs.org/ Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines You received this message because you are subscribed to the Google Groups "nodejs" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nodejs?hl=en?hl=en
