title: Can I receive more bytes in one transfer from this c# to android device?
body: <p>I'm trying to transfer a long string (2286 bytes) over Bluetooth. I've a bit of an issue about receiving a long json string over the bluetooth.. Well, not an issue, because it is receiving it, but in the manner it is receiving it. I was wondering if it was possible to receive more bytes in one transfer or if it's just a limitation.</p>
  
  <p>OK, so on the c# side.. Here's the server loop..</p>
  
  <pre><code> _screenWriterCallBT("Bluetooth Server started, waiting for clients..");
          BluetoothListener blueListener = new BluetoothListener(mUUID);
          blueListener.Start();
          BluetoothClient conn = blueListener.AcceptBluetoothClient();
          _screenWriterCallBT("Bluetooth Client has connected");
  
          Stream mStream = conn.GetStream();
          while (true)
          {
              try
              {
                  byte[] recieved = new byte[1024];
                  mStream.Read(recieved, 0, recieved.Length);
                  string content = Encoding.ASCII.GetString(recieved);
                  _screenWriterCallBT("Recieved: " + content + "via bluetooth");
  
                  ParseJson parseJson = new ParseJson();
                  JsonReturn = parseJson.InitialParsing(content); //parse message
  
                  byte[] sent = Encoding.ASCII.GetBytes(JsonReturn);
                  mStream.Write(sent, 0, sent.Length);
                  _screenWriterCallBT("Test" + sent.Length);
                  string messageSent = Encoding.ASCII.GetString(sent);
                  _screenWriterCallBT("sent via Bluetooth: " + messageSent);
              }
              catch (IOException exception)
              {
                  _screenWriterCallBT("Bluetooth Client has disconnected. Exception:" + exception + "\n");
              }
          }
  </code></pre>
  
  <p>It seems to work. </p>
  
  <pre><code>_screenWriterCallBT("Test" + sent.Length); // says 2286 bytes on the long string i'm trying to send.
  </code></pre>
  
  <p>On the Android side I have a server listening and sending too:</p>
  
  <pre><code> public void run() {
      byte[] buffer; 
      int bytes;
  
      while (true) {
          try {
              buffer = new byte[1024];
              // Read from the InputStream
              bytes = mmInStream.read(buffer);
  
              System.out.println(bytes);
  
              if(bytes != 0)
                  listener.messageReceivedFromServer(MESSAGE_READ, bytes, -1, buffer);
          } catch (IOException e) {
              break;
          }
      }
  
  }
  </code></pre>
  
  <p>It works, and receives the bytes, but it receives them in an odd way. </p>
  
  <pre><code>System.out.println(bytes); prints 1010, 1010, 266
  </code></pre>
  
  <p>So, basically i'm getting a truncated json string every time and I can't turn that into a JSON object.  I had an idea of when a message was received, it writes it to a temporary string, and it tests if it is a valid json object then carries on until its valid. Anyway, I thought i'd come check if any Stack overflow guru's could shine any light on if i'm doing something wrong or can change something?</p>
  
  <p>Cheers
  Ben</p>