title: Android UDP Socket - Receiving "Garbage"
body: <p>OK so at the moment I am trying to create an Android Game, I have a Thread running which is fine. </p>
  
  <p>However I am unsure of how to determine how big the incoming buffer size, and how to read it.</p>
  
  <p>Currently this is my code:</p>
  
  <pre><code>        if(!thisPlayer.isHost)
          {
  
              byte[] incMsg = new byte[64];
              try {
                  socket = new DatagramSocket(port);
                  //socket.setSoTimeout(10);
                  DatagramPacket packet = new DatagramPacket(incMsg, incMsg.length);
                  socket.receive(packet);
                  Log.d("Receiving Game Message", "Received"+incMsg.toString());
              } catch (UnknownHostException err) {
                  Log.e("", "", err);
              } catch (Exception err) {
                  Log.e("", "", err);
              }  
              testString = incMsg.toString();
          } else {
              byte[] msg = "Game On".getBytes();
              try {
                  String compIP = "192.168.1.102";
                  String ip;
                  if(thisPlayer.ipAddress.equals(compIP))
                      ip = "192.168.1.107";
                  else
                      ip = compIP;
                  InetAddress sendingIP = InetAddress.getByName(ip);
                  socket = new DatagramSocket(port);
                  DatagramPacket p = new DatagramPacket(msg, msg.length, sendingIP, 5130);
                  socket.send(p);
                  Log.d("Sending Game Message", "Sent");
                  socket.close();
              } catch (UnknownHostException err) {
                  Log.e("", "",  err);
              } catch (Exception err) {
                  Log.e("", "", err);
              } 
          }
          socket.close();
  </code></pre>
  
  <p>This kind of works. The Host is sending data. The Client is receiving data (I have commented out the sotimeout and the thread continues, so I know its receving data).</p>
  
  <p>I convert the byte[] to a string and then display it. However what is displaying is "[B@448xxxx" where xxxx is a series of repeating numbers/letters.</p>
  
  <p>Unfortunately I am up to the point where I am getting frustrated and now clouded brain, and cannot think for the life of me where I have gone wrong.</p>
  
  <p>TIA</p>
  
  <p>p.s. I have even tried making the receiving byte array the same size as the outgoing, without any luck :/</p>