Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This isn't a display / presentation problem. This is a problem related to data transmission protocols. Socket is a stream oriented protocol which means it isn't message based. Meanwhile you are using it like it is message based - which you can do but then you need to define a protocol for your sender and receiver to identify the start and end of each message.</p> <p>Having said this and based on what you are asking I'm assuming that you've settled on using a newline (or some variant of one) as your message end marker. To make this work properly you need to actively look for that newline in the incoming data so you can recognize the end of each message as well as strip it off prior to processing.</p> <p>The following code should replace your socket.on method to get the result you want.</p> <pre><code>// define your terminator for easy reference, changes var msgTerminator = '\n'; // create a place to accumulate your messages even if they come in pieces var buf; socket.on('data', function(data){ // add new data to your buffer buf += data; // see if there is one or more complete messages if (buf.indexOf(msgTerminator) &gt;= 0) { // slice up the buffer into messages var msgs = buf.split(msgTerminator); for (var i = 0; i &lt; msgs.length - 2; ++i) { // walk through each message in order var msg = msgs[i]; // pick off the current message console.log('Data in server, sending to handle()'); // send only the current message to your handler worker.handle(msg, socket); } buf = msgs[msgs.length - 1]; // put back any partial message into your buffer } }); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload