what is the library should I use ? what are the functions that help me?
ObjectOutputStream/ObjectInputStream.
The whole logic is approximately as follows. Adjust by the demands of your app.
Send:
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(objectToSend);
oos.close();
byte[] bytes = baos.toByteArray();
socket.write(bytes);
Receive:
ObjectInputStream ois = new ObjectInputStream(socketInputStream);
MyObject mo = (MyObject)ois.readObject();