Note that there are some explanatory texts on larger screens.

plurals
  1. PONode buffer printing issues
    primarykey
    data
    text
    <p>I'm trying to make a Java TCP client and a node.js TCP server talk together. This is my code at the moment :</p> <ul> <li><p>The Java client</p> <p>import java.net.<em>; import java.io.</em>;</p> <p>public class Client2{ </p> <pre><code>public static void main(String[] args) throws Exception{ Socket s = new Socket("192.168.1.35",8500); DataOutputStream dos = new DataOutputStream(s.getOutputStream()); dos.writeUTF("abcdefgh"); dos.close(); s.close(); } </code></pre> <p>}</p></li> <li><p>the Node.js Server</p> <p>var net = require('net'), server = net.createServer();</p> <p>server.on('connection', function (client) {</p> <pre><code>console.log('Hello World !'); client.on('data', function(data) { var message = data.toString('utf8'); console.log('***' + message +'***'); }); </code></pre> <p>});</p> <p>server.listen(8500);</p></li> </ul> <p>This example will give this result back :</p> <pre><code>Hello World ! **abcdefgh*** </code></pre> <ul> <li><p>but with this as input :</p> <p>abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz</p></li> </ul> <p>it gives this back :</p> <pre><code>Hello World ! ***�abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz*** </code></pre> <ul> <li><p>with this input :</p> <p>qq32we3w87d 38s1d87s4df7s4d1+s2d7f+sfdsf4sà$àà3663%ç%&amp;ç%&amp;ç</p></li> </ul> <p>it gives this back :</p> <pre><code>Hello World ! ***@qq32we3w87d 38s1d87s4df7s4d1+s2d7f+sfdsf4sà$àà3663%ç%&amp;ç%&amp;ç*** </code></pre> <p><strong>tldr: Sometimes when logging the buffers, node adds characters (rectangles with numbers or ?) at the beginning or event cuts some characters at the start out.</strong></p> <p><strong>- How can I log buffers and assign them to a variable the right way ?</strong></p>
    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.
    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