• Post Reply Bookmark Topic Watch Topic
  • New Topic

Trying to use ObjectOutputStream with Sockets but it doesn't seem to work, need help!  RSS feed

 
Alex Bien-Aime
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The server side of my application is using a ObjectOutputStream to send data I serialized in a class which implements Externalizable.
...
objOut = new ObjectOutputStream(serverSoc.getOutputStream());
...
The Server is correctly recieving the Inputstream form the client threw a BufferedReader. which tells the server to send the stream with the desired info
So then what I do is pass my ObjectOutputStream instance as a parameter to the "tu.writeExternal(ObjOut)" method of my Externalizable class in which I write all the object I want serialized. This doesn't seem to work because when my client tries to read the Inputstream I get nothing and the client just stals there. I would like to know if it's even possible to use ObjectOutputStream or must I use a DataOutputStream, thank you!
code sample:
//Server
do
{

lect = in.readLine();
if (!lect.equals("null"))
{
lecture.insert(0,lect);
commandString = lecture.toString();
commandString = commandString.trim(); // enlever espace blanc


if (commandString.equals("GET"))
{
objOut.flush();
tu.writeExternal(objOut);

}
}while(!commandString.equals("END"));
//CLient
...
objIn = new ObjectInputStream(clientSocket.getInputStream());
...
objIn.readInt()//stals here
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
First thing, writeExternal doesn't work they way you use it. I guess some tutorial on Externalizable would help more here.
But to address the issue,
- We have to get ObjectOutputStream oos = clientSocket.getOutputStream() and then say,
- oos.writeObject(tu);
this would invoke writeExternal on tu object and should work the way you are expecting..
I hope I hit at the correct problem here...
Regards
Maulin
 
Alex Bien-Aime
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
Thanks but I should of shown more detail. I pass my ObjectOutpusSream to the method and in there I write the Objects I want serialized.
public class TestUpdate implements Externalizable {
private h = new House(duplex);
...
...
public void writeExternal(ObjectOutput out)throws IOException
{
out.writeInt(a);
out.writeInt(b);
out.writeInt(c);
out.writeInt(d);
out.writeInt(h);
}
...
}
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!