0

I recently use ObjectOutputStream to write objects in TCP/IP socket programming.

If I want to write a large size of List<Object>/ArrayList<Object> through the socket

(e.g. list.size: 100, the total bytes may larger than the payload size),

should I just call writeObject(List<Object>/ArrayList<Object>)?

Is that OK, or any Exception occurs?

Does ObjectOutputStream automatically split the list to a few segments before sending the packets? Or it doesn't support?

Is there another way to send a large size of an object?

As for ObjectInputStream, can I just call readObject() to receive the large size of List<Object>/ArrayList<Object>?

Thanks in advance.

->

Another questions: Does ObjectInputStream receive anything when the list is not fully sent from the sender? I want to close the socket but the ObjectOutputStream is still sending the list. Does it shutdown immediately when I close socket, and the list segments are destroyed?

2 Answers 2

1

Is that OK, or any Exception occurs? It's ok.

Does ObjectOutputStream automatically split the list to a few segments

Yes.

before sending the packets? Or it doesn't support?

The underlying socket has no control over how packets are sent. Nor should you need it.

Is there another way to send a large size of an object?

Many but 100 isn't very large. If you had a few million of large objects it might be worth it. If you have a few billion you definitively need to consider alternatives. There is lots of alternatives but I wouldn't bother unless you need it.

As for ObjectInputStream, can I just call readObject() to receive the large size of List/ArrayList?

Yes, that is what it is for.

Sign up to request clarification or add additional context in comments.

1 Comment

Another questions: Does ObjectInputStream receive anything when the list is not fully sent from the sender? I want to close the socket but the ObjectOutputStream is still sending the list. Does it shutdown immediately when I close socket, and the list segments are destroyed?
1

should I just call writeObject(List<Object>/ArrayList<Object>)?

Yes.

Is that OK, or any Exception occurs?

It is OK, but exceptions can always occur, especially over a network.

Does ObjectOutputStream automatically split the list to a few segments before sending the packets? Or it doesn't support?

Yes, and TCP does as well, and IP.

Is there another way to send a large size of an object?

Why? You have this way. You don't need another way.

As for ObjectInputStream, can I just call readObject() to receive the large size of List<Object>/ArrayList<Object>?

Yes.

2 Comments

Another questions: Does ObjectInputStream receive anything when the list is not fully sent from the sender? I want to close the socket but the ObjectOutputStream is still sending the list. Does it shutdown immediately when I close socket, and the list segments are destroyed?
You will get an EOFException if the object isn't fully received before end of stream.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.