title: writing/reading number of bytes to/from socket data in Dart
body: <p>In the following server/client socket code, the server tries to send ints from 0 to 1023. The client receives the right number of ints but they wrap at 255. Why is this and what is the proper way?</p>
  
  
  
  <h3><strong>* Server *</strong></h3>
  
  <pre class="lang-dart prettyprint-override"><code>import 'dart:async';
  import 'dart:io';
  
  main() async {
    final server = await ServerSocket.bind('127.0.0.1', 4041);
    server.listen((Socket socket) {
      print('Got connected ${socket.remoteAddress}');
      for(int i=0; i&lt;1024; i++) {
        socket.add([i]);
      }
      socket.close();
      print('Closed ${socket.remoteAddress}');
    });
  }
  </code></pre>
  
  <h3><strong>* Client *</strong></h3>
  
  <pre class="lang-dart prettyprint-override"><code>import 'dart:async';
  import 'dart:io';
  
  main() async {
    final client = await Socket.connect('127.0.0.1', 4041);
    client.listen(
        (var data) =&gt; print('Got $data'),
        onDone: () { print('Done'); client.close(); },
        onError: (e) { print('Got error $e'); client.close(); });
    print('main done');
  }
  </code></pre>
  
  <p>Also, it feels like the Socket api is a bit different - being more Dartish than other languages the way it supports reading as a stream. But what if you just want to read <em>N</em> bytes? How do you achieve that? I see the <em>take</em> method (<em>Stream take(int count)</em>) but I'm not clear on what exactly <em>count</em> is taking, especially in terms of how many bytes have been read. Because Socket implements <em>Stream&lt; List &lt; int > ></em> and because int is not really a fixed size entity (I think??), how do you know how many bytes have been read?</p>