title: Flutter compute and network requests
body: <p>I am building an application that has its own high level protocol that runs over TCP,
  thus I am using <code>RawSocket</code> and <code>RawServerSocket</code> to handle TCP communications.
  I have a static class that handles the communications and the logic of which message should I respond to first (Used various messaging queues to handle that).
  With flutter being Single Threaded, in order to not hang the main UI I created a <code>Peridic Timer</code> that checks if there are new messages in the message queue every 2.5 seconds (the messages enter the queue thanks to the event listener of the socket), then I handle the messages and the UI seems to run smooth.</p>
  
  <p>I had the feeling that if I were to send a large amount of data such as an image or a song, I would hang up the Event looper due to it reading from the socket.
  So I tried to create a <code>callback function</code> to handle read/write events and call it up using the <code>compute</code> method so that it'll run on its own <code>Isolate</code> and return me the data once finished.</p>
  
  <pre><code>Uint8List readFromTcpSocketCallback(Map&lt;String, dynamic&gt; m){
    return (m[ConstantValues.tcpSocketDefinitionForMap.toString()] as RawSocket).read(m[ConstantValues.amountReadDefinitionForMap.toString()]);
  }
  
  class Communications{
  ...
  static Future&lt;Uint8List&gt; _readAllFromTcpSocket(RawSocket socket, int length)async{
      Uint8List finalBufferReceived;
      Uint8List buffer;
      int amountRead = 0;
      do
      {
        buffer = await compute(readFromTcpSocketCallback, {ConstantValues.tcpSocketDefinitionForMap.toString() : socket, 
        ConstantValues.amountReadDefinitionForMap.toString() : length - amountRead});
        amountRead += buffer.length;
        finalBufferReceived.isEmpty ? finalBufferReceived = buffer : finalBufferReceived.addAll(buffer);
      }
      while(amountRead &lt; length);
      return finalBufferReceived;
    }
  }
  </code></pre>
  
  <p>Unfortunately, I encountered the <code>exception</code> : <code>flutter Illegal argument in isolate message object extends Native Wrapper...</code></p>
  
  <p>This is obviously caused due to me attempting to send the <code>RawSocket</code> as it is, if I were to be able to encode it to a json string or some binary representation of it and then decode it inside the callback function this would work, but I don't seem to find an actual way to establish that.</p>
  
  <p><strong>My question is</strong>:
  How can I somehow send the <code>socket</code> over to the <code>callback function</code> while using <code>compute</code>?
  And, is the <code>Read/Write</code> operation of the socket <strong>managed in its own <code>Isolate</code></strong> ?, because if they are, then I really don't need to use <code>compute</code> at all.
  I was unable to find information about this, apart from flutter stating that <code>compute</code> can send <code>primative types</code> only.
  Creating an <code>Isolate</code> and applying complex logic in it's send/recv methods seems like an overkill to establish such a simple thing.
  I really don't understand how the Flutter team excpects us to create applications that run smoothly with one thread (yes, they support async operations, but that is still managed on one single thread which makes large network operations really painful, <strong>that is if the RawSocket Read/Write operations are NOT run on a different Isolate</strong>)</p>