I am trying to send a custom Object (Info) using a socket from a server to a client. Info class code is:

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class Info implements Serializable {

    private static final long serialVersionUID = -8967456786256719218L;

    private String ip;
    private int port;
    private List<String> responsibilityLines;

    public Info(String ip, int port, List<String> responsibilityLines) {
        this.ip = ip;
        this.port = port;
        this.responsibilityLines = responsibilityLines;

    public String getIp() {
        return ip;

    public void setIp(String ip) {
        this.ip = ip;

    public int getSubscriberPort() {
        return port;

    public void setSubscriberPort(int port) {
        this.port = port;

    public List<String> getResponsibilityLines() {
        return responsibilityLines;

    public void setResponsibilityLines(ArrayList<String> responsibilityLines) {
        this.responsibilityLines = responsibilityLines;

    public String toString() {
        return "Info{" +
                "ip='" + ip + '\'' +
                ", port=" + port +
                ", responsibilityLines=" + responsibilityLines +

The socket connection is established and any other java object or primitive type is sent successfully. However when I try to send a List of Info objects, the client blocks and wait to receive (which never happens). To send the object from the server I use:

 List<Info> infoList = new ArrayList<>();
 Info inf = new Info("", 3456, null);

and to receive the object I use:

List<Info> infoList;
infoList = (List<Info>) dis.readObject();

where dos is the ObjectOutputStream and dis is the ObjectInputStream.

1 Answers

Murtaza Khursheed Hussain On

Use ByteArrayOutputStream as an inpute to ObjectOutputStream()

ByteArrayOutputStream bos = new ByteArrayOutputStream()
ObjectOutputStream oos = new ObjectOutputStream(bos)

given that your server knows who to parse info class.