Hi Juan,
It's because the socket has a buffer and it's not flush everytime you write
on it.
If you want to send multiple message, you can use client.end('a'); instead
of client.write('a');
You don't need to write client.end(); because you socket is already
half-closed by the client.end('a');
Regards,
Clément
Le dimanche 19 août 2012 21:01:09 UTC+2, Juan Ignacio Dopazo a écrit :
>
> Hi!
>
> I'm getting a weird result when writing to a socket. I wrote a simple
> experiment with a client and a server:
>
> server.js
> var net = require('net');
>
> net.createServer(function (connection) {
> console.log('client connected');
> connection.on('data', function (data) {
> console.log('data: ' + data);
> });
> }).listen(1337);
>
> client.js
> var net = require('net');
>
> var client = net.connect({port: 1337}, function () {
> console.log('connected');
> var i = 0;
> function send() {
> client.write('a');
> if (++i < 100) {
> process.nextTick(send);
> } else {
> client.end();
> }
> }
> send();
> });
>
> I expected the server to show 100 lines of data: a, but I ended up
> getting a smaller number of data: aaaaaaa lines. There's
> socket.setNoDelay() that seems to be what I want, but it doesn't seem to
> have any effect.
>
> What am I missing?
>
> Thanks a lot,
> Juan
>
--
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