Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ObjectOutput/InputStream Initializing

Status
Not open for further replies.

MagiMike

Technical User
Jun 5, 2003
44
SE
Hi,
I'm creating a chat-application consisting of a client and a server. Both these programs use a specific thread to get data from the other.
The sending of the data takes place in the GUI-thread (event-thread?).

The creation of the ObjectStreams looks like this:

CLIENT-side
socket = new Socket(InetAddress.getByName(ipadr), 12345);

output = new ObjectOutputStream(socket.getOutputStream());
output.flush();

input = new ObjectInputStream(socket.getInputStream());


SERVER-side
Socket sock = serverSocket.accept();

output = new ObjectOutputStream(sock.getOutputStream());
output.flush();

input = new ObjectInputStream(sock.getInputStream())


Anyhow, (it seems to be pretty random) sometimes the first message sent on a stream doesn't reach the other application. It seems like sometimes the ObjectStreams are not initialized completely.

Are there some known problem I should avoid when creating the streams and using them in different threads (only one thread sending and one thread reading)?

The objects I send is of a class Message and it's subclasses containing only a String or a String-array. String-arrays are Serializable, right?

/ Mike
 
If you send Stringmessages, why do you use Object-Streams?
They are meant for exchanging complicated Objects, which are build of other Objects, and so on, when the other side shall be able to restore the Object.

Does the sender recognize, that the sending fail?
Can you send it again then?

seeking a job as java-programmer in Berlin:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top