posted 10 years ago
Well, how are the objects serialized in the first place? My guess is, someone just serialized one or more objects, then closed the stream. You code, on the other hand, assumes that there will be a null reference sent. Apparently, there isn't one, and you get EOF instead.
Basically, both sender and receiver need to agree on a communication protocol. In this case, you've presumably agreed on what type of objects are being sent, but you don't know how to tell when the objects are done. There are several possibilities:
1. Agree on a special value that will be sent to indicate the end of your objects. Null is a good possibility. In that case, have the sender be sure and send a null, before they close the stream.
2. Before your list of objects, send an int representing the number of objects that will be sent. Then loop that number of times, and exit.
3. Wrap the objects in an array or list, and serialize that instead.
4. Just catch the EOFException and move on. That's the signal for the end of your processing.
Options 1-3 require the sender to change their code, as well as the receiver. You may or may not be able to do this. Options 2 and 3 require that you know how many objects there are before you send them. You may or may not be able to do this, as well. Personally I like option 1 best, but if you can't get the sender to change their code, option 4 may be your only option.