node.js - NodeJS (coffeescript): TCP socket only writing intermittently -


i having trouble setting simple simple server using net module in nodejs keeps each tcp socket open once connected, reads data socket , replies/writes data socket after each line of text received.

i receiving data lines/chunks/requests , each 1 write response string socket. however, of written responses being received client.

below simplified code server:

net = require('net')  server = net.createserver() nl = string.fromcharcode(10)  server.on('connection', (socket) ->   console.log('net server connection')    handle = (data, next) ->     if data.tostring().indexof('@command;') > -1       console.log("sending: #{"@none\n"}")       socket.write("@none#{nl}", next)     else       console.log("sending: mf;ok;9999-9999")       socket.write("mf;ok;9999-9999#{nl}", next)    socket.on('end', () ->     console.log('client disconnected')   )    socket.on('data', (data) ->     console.log("recieved: #{data}")     console.log("pausing")     socket.pause()     handle(data, () ->       socket.resume()       console.log("resuming")     )   )    socket.on('error', (err) ->     winston.error("socket error: ", err)   ) )  server.on('listening', () -> console.log('net server listening')) server.on('error', (err) -> console.log('net server error', err)) server.on('close', (err) -> console.log('net server close')) server.listen(8888) 

the client not have control on has been tested working fine.

this desired output:

tx: @tr;mf;1234;3;1;1;999999;12345;# rx: mf;ok;9999-9999 tx: @tr;mf;1235;2;1;11111;22222;33333;44444;1;2;13579;30.23;1090.23;0;1;12345;# rx: mf;ok;9999-9999 tx: @command;12345 rx: @none 

and actual output: (you'll notice line 4 missing).

tx: @tr;mf;1234;3;1;1;999999;12345;# rx: mf;ok;9999-9999  tx: @tr;mf;1235;2;1;11111;22222;33333;44444;1;2;13579;30.23;1090.23;0;1;12345;# tx: @command;12345 rx: @none 

and here console.log output in terminal:

net server connection recieved: @tr;mf;1234;3;1;1;999999;12345;# pausing sending: mf;ok;9999-9999 resuming recieved: @tr;mf;1235;2;1;11111;22222;33333;44444;1;2;13579;30.23;1090.23;0;1;12345;# pausing sending: mf;ok;9999-9999 resuming recieved: @command;12345 pausing sending: @none 

where going wrong!? in advance

there nothing wrong code. problem on client side. need need answers. thanks


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -