By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,952 Members | 1,725 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,952 IT Pros & Developers. It's quick & easy.

object output stream on socket

P: n/a
Hi!

I have made a client and a server which are supposed to communicate by
sending java objects. They don't.
I have managed to send an object from the client to the server. But
continuing after that I can't do the opposite. I want the program to send an
object-reply from the server to the client. But on this step boths sides
throw a socket exception.
From println's I have figured out that it can't set up on either side the
corresponding stream: output stream for the server and input stream for the
client.
I have closed the input stream on the server and the output stream on the
client from the first sending of the object.
The object that's being sent does implement serializable.

The blocks of code of setting up the streams are below.
Any help would be greatly appreciated.
Maria

Here is the code the client is running to receive (it throws the exception
just after the println statement):
System.out.println("in receive");
InputStream in = client.getInputStream();
ObjectInputStream receive = new ObjectInputStream(in);
Object received = receive.readObject();
receive.close();
in.close();

Here is the code the server is running to send (it throws the exception just
after the println statement):

System.out.println("in send");
OutputStream out = connection.getOutputStream();
System.out.println("got stream one");
ObjectOutputStream sendStream = new ObjectOutputStream(out);
sendStream.writeObject(toSend);
sendStream.close();
out.close();
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a

"Maria Gaitani" <M.*******@warwick.ac.uk> wrote in message
news:40***********************@lovejoy.zen.co.uk.. .
Hi!

I have made a client and a server which are supposed to communicate by
sending java objects. They don't.
I have managed to send an object from the client to the server. But
continuing after that I can't do the opposite. I want the program to send an object-reply from the server to the client. But on this step boths sides
throw a socket exception.
From println's I have figured out that it can't set up on either side the
corresponding stream: output stream for the server and input stream for the client.
I have closed the input stream on the server and the output stream on the
client from the first sending of the object.
The object that's being sent does implement serializable.

The blocks of code of setting up the streams are below.
Any help would be greatly appreciated.
Maria

Here is the code the client is running to receive (it throws the exception
just after the println statement):
System.out.println("in receive");
InputStream in = client.getInputStream();
ObjectInputStream receive = new ObjectInputStream(in);
Object received = receive.readObject();
receive.close();
in.close();

Here is the code the server is running to send (it throws the exception just after the println statement):

System.out.println("in send");
OutputStream out = connection.getOutputStream();
System.out.println("got stream one");
ObjectOutputStream sendStream = new ObjectOutputStream(out);
sendStream.writeObject(toSend);
sendStream.close();
out.close();


If you close the streams you also close the underlying socket connections.
Is that your intention? If not simply flush the streams instead.

Silvio Bierman
Jul 17 '05 #2

P: n/a
Thank you very much for your time and help !!
I will try that straight away !

Maria

"Maria Gaitani" <M.*******@warwick.ac.uk> wrote in message
news:40***********************@lovejoy.zen.co.uk.. .
Hi!

I have made a client and a server which are supposed to communicate by
sending java objects. They don't.
I have managed to send an object from the client to the server. But
continuing after that I can't do the opposite. I want the program to send an object-reply from the server to the client. But on this step boths sides
throw a socket exception.
From println's I have figured out that it can't set up on either side the
corresponding stream: output stream for the server and input stream for the client.
I have closed the input stream on the server and the output stream on the
client from the first sending of the object.
The object that's being sent does implement serializable.

The blocks of code of setting up the streams are below.
Any help would be greatly appreciated.
Maria

Here is the code the client is running to receive (it throws the exception
just after the println statement):
System.out.println("in receive");
InputStream in = client.getInputStream();
ObjectInputStream receive = new ObjectInputStream(in);
Object received = receive.readObject();
receive.close();
in.close();

Here is the code the server is running to send (it throws the exception just after the println statement):

System.out.println("in send");
OutputStream out = connection.getOutputStream();
System.out.println("got stream one");
ObjectOutputStream sendStream = new ObjectOutputStream(out);
sendStream.writeObject(toSend);
sendStream.close();
out.close();

Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.