Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

ObjectInput/OutputStream with Sockets

6 views
Skip to first unread message

Shahzad Bhatti

unread,
Jul 24, 1997, 3:00:00 AM7/24/97
to

I wrote a simple client/Server program using sockets and I used
DataInputStream/DataOutputStream to send and receive messages.
But when some messages I recieve on server from client have different
data from what I sent, where part of the data is from previous
message. Here is layout of client program
_client = new _out = new Socket(_host, _port);
_out = new ObjectOutputStream(_client.getOutputStream());
_in = new ObjectInputStream(_client.getInputStream());

sending request
_out.writeObject(someObject);
receive request
messageReply = (Cast Object) _in.readObject();


Server is multithreaded, e.g.

while (true) {
Socket clientSocket = _listenSocket.accept();
if (_target == null) {
fail("DynamicMessageServer target is null");
}
Worker worker
= new Worker(clientSocket);
}


Worker extends Thread {
....
run() {
for (;;) {
Request req = _in.readObject();
.....
_out.writeObject(replyObject);
}
}


I am not sure why when I receive the message, part of the
message is from previous message. By the way, any objects that
I send implement Serializable, I am not sure if I need to
implement Clonable? Any ideas????
Thanks.
-shahzad

0 new messages