You are thinking about a
protocol, a wrapper around the data so your server and client can converse.
The simplest options off the top of my head:
-close the stream when you are done writing data, then the receiving end gets an EOF
-if you want to keep the socket open for a prolonged conversation, use the Object*putStreams to read/write
Java objects
- another option is to precede any data with a value indicating the length of the message. If you are transmitting various kinds of data you could also include a value indicating which kind of data or even what kind of message you are sending.