I cut my teeth with TCP sockets and am confused by the way the messages arrive in my application. It looks like they are broken. Does anyone know how I can join them together? All messages are separated by a line break (\ r \ n)
var stream = net.createConnection(port,host); stream.setEncoding("utf8"); stream.on('data', function(chunk){ console.log('data: ' + sys.inspect(chunk)); });
An example of what the console unloads is as follows:
data: '0' data: '5293800791D04\r' data: '\n' data: '053138007928F1\r\n' data: '05313800012869\r\n' data: '052E3800790E0E\r\n' data: '052E3800010E86\r\n' data: '05223' data: '8007933F5\r\n' data: '05213800791019\r\n' data: '05213800795C795B79265A\r\n' data: '05213800011091\r\n'
I need to break the material on the line so that I don't have incomplete messages. Is there a way to tell node to do this for me? If not, does anyone have any examples of how this can be done?
source share