title: Send and receive serialize object on UDP
body: <p>I am trying to send a serialized object from a server process to a client process in Java using UDP. The problem is that the client is being blocked on the receive method. Can someone help?!</p>
  
  <p>here is the server code for sending the object:</p>
  
  <pre><code>  ClientModel C1= new ClientModel(100,"Noor","Noor",38,38,"asd");
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(baos);
    oos.writeObject(C1);
    oos.flush();
    byte[] Buf= baos.toByteArray();
    packet = new DatagramPacket(Buf, Buf.length, client, port);
    socket.send(packet);
  </code></pre>
  
  <p>and here is the client code for receiving the object:</p>
  
  <pre><code>byte[] buffer = new byte[100000];
  packet = new DatagramPacket(buffer, buffer.length );
  socket.receive(packet);
  System.out.println("packet received");
  </code></pre>
  
  <p>I just want to receive the object to be able to reconstruct but I cannot receive the packet itself.</p>