473,327 Members | 1,920 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

object output stream on socket

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
2 10423

"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Jim P. | last post by:
I'm having trouble returning an object from an AsyncCallback called inside a threaded infinite loop. I'm working on a Peer2Peer app that uses an AsyncCallback to rerieve the data from the remote...
8
by: rawCoder | last post by:
Hi All, I need some advanced samples or references for passing custom objects over the network using sockets. Without using Remoting what are other options in .NET Framework for this binary...
0
by: vinothgsd | last post by:
Hi, I have created Client/Server application. In that Client side Program i have used Asynchronous Callback method for send and receive the stream. In the Receive method I want to make the...
7
by: simonrigby_uk | last post by:
Hi all, Sorry if this is the incorrect group but I couldn't see anything directly relevant. Can someone confirm for me what happens when two network streams are sent to an application at the...
5
by: ad | last post by:
I used use SharpZipLib to compress files in disk. But now I want to compress stream into another stream in memory(the stream not associated with disk file) My pseudo is: Stream...
4
by: Lee Gillie | last post by:
What I am hoping to do is make a constructor for a derived class that can accept an instance of the base class. Maybe this just is not possible? I am working with the new SSLStream in the 2005...
0
by: ChopDown | last post by:
Hi, I want to send/receive a serializable object in socket: ==========sender========== Dim MyMessage As New MessageClass.Message() Dim client As New TcpClient...
2
by: White Spirit | last post by:
I have a function within an application where a client connected to a server continuously sends data. The code on the server side is of the following form: Socket socket = receiveSocket;...
2
by: darthghandi | last post by:
I am creating a listener class that listens for incoming connections. When I get an incoming connection, I want to signal an event to happen and pass that connected socket to a different thread...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.