title: Java UDP - Packet Send Problem
body: <p>Everytime I try to send a UDP packet to an address I get the following exception:</p>
  
  <pre><code>java.lang.ArrayIndexOutOfBoundsException
      at java.net.PlainDatagramSocketImpl.send(Native Method)
      at java.net.DatagramSocket.send(DatagramSocket.java:625)
      at services.servicetypes.network.host.Server_UDP_Thread_Monitor.send(Server_UDP_Thread_Monitor.java:84)
  </code></pre>
  
  <p>Which points directly to the socket send function - this.socket.send(packet);</p>
  
  <p>After placing a break point on my datagram packet I get the following info:</p>
  
  <pre><code>packet  DatagramPacket  java.net.DatagramPacket@52c4c57 
  byte[]  #1248(length=16)    
  offset  int 0   
  length  int 16  
  bufLength   int 16  
  address Inet4Address    /192.168.0.101  
  Static          
  Inherited   
  port    int 3889
  </code></pre>
  
  <p>I'm not clear on why this is occuring, if anyone could shed any light on the problem that would be great. My inital thoughts were perhaps one of the datagram packet elements was empty.</p>
  
  <p>(Basic source)</p>
  
  <pre><code>ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
  DataOutputStream out = new DataOutputStream(byteOut);
  
  // Game type
  out.writeInt(1);
  
  // Client
  out.writeInt(gamerToSend.getClientID());
  
  // Position
  out.writeFloat(gamerToSend.getX());
  out.writeFloat(gamerToSend.getY());
  
  
  DatagramPacket packet = new DatagramPacket
  (
    byteOut.toByteArray(),
    byteOut.size(),
    gamerToSend.getInetAddress(),
    3887
  );
  
  this.socket.send(packet);
  
  byteOut.close();
  out.close();
  </code></pre>
  
  <p>INetAddress info: (Ip is correctly displaying destination machine)</p>
  
  <pre><code>address Inet4Address    /192.168.0.101  /192.168.0.101  
  Static      
  INADDRSZ    int 4   4   
  serialVersionUID    long    3286316764910316507 3286316764910316507 
  loopback    int 2130706433  2130706433  
  IPv4    int 1   1   
  IPv6    int 2   2   
  preferIPv6Address   boolean false   false   
  nameService InetAddress$1   java.net.InetAddress$1@5bf0cf51 java.net.InetAddress$1@5bf0cf51 
  serialVersionUID    long    3286316764910316507 3286316764910316507 
  addressCache    InetAddress$Cache   java.net.InetAddress$Cache@1ebafdff java.net.InetAddress$Cache@1ebafdff 
  negativeCache   InetAddress$Cache   java.net.InetAddress$Cache@679801c  java.net.InetAddress$Cache@679801c  
  addressCacheInit    boolean true    true    
  unknown_array   InetAddress[]   #1266(length=1) #1266(length=1) 
  impl    Inet6AddressImpl    java.net.Inet6AddressImpl@12c9b196  java.net.Inet6AddressImpl@12c9b196  
  lookupTable HashMap "size = 0"  "size = 0"  
  $assertionsDisabled boolean true    true    
  Inherited               
  hostName                
  address int -1062731675 -1062731675 
  family  int 2   2   
  canonicalHostName               
  caport  int 3889    3889    
  </code></pre>
  
  <p>Server source
  <a href="http://pastebin.com/JCdjhFQM" rel="nofollow">http://pastebin.com/JCdjhFQM</a></p>