object output stream on socket

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Maria Gaitani

    #1

    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.prin tln("in receive");
    InputStream in = client.getInput Stream();
    ObjectInputStre am receive = new ObjectInputStre am(in);
    Object received = receive.readObj ect();
    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.prin tln("in send");
    OutputStream out = connection.getO utputStream();
    System.out.prin tln("got stream one");
    ObjectOutputStr eam sendStream = new ObjectOutputStr eam(out);
    sendStream.writ eObject(toSend) ;
    sendStream.clos e();
    out.close();


  • Silvio Bierman

    #2
    Re: object output stream on socket


    "Maria Gaitani" <M.Gaitani@warw ick.ac.uk> wrote in message
    news:403820bb$0 $24603$fa0fcedb @lovejoy.zen.co .uk...[color=blue]
    > 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[/color]
    an[color=blue]
    > 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[/color]
    the[color=blue]
    > 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.prin tln("in receive");
    > InputStream in = client.getInput Stream();
    > ObjectInputStre am receive = new ObjectInputStre am(in);
    > Object received = receive.readObj ect();
    > receive.close() ;
    > in.close();
    >
    > Here is the code the server is running to send (it throws the exception[/color]
    just[color=blue]
    > after the println statement):
    >
    > System.out.prin tln("in send");
    > OutputStream out = connection.getO utputStream();
    > System.out.prin tln("got stream one");
    > ObjectOutputStr eam sendStream = new ObjectOutputStr eam(out);
    > sendStream.writ eObject(toSend) ;
    > sendStream.clos e();
    > out.close();
    >
    >[/color]

    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


    Comment

    • Maria Gaitani

      #3
      Re: object output stream on socket

      Thank you very much for your time and help !!
      I will try that straight away !

      Maria

      "Maria Gaitani" <M.Gaitani@warw ick.ac.uk> wrote in message
      news:403820bb$0 $24603$fa0fcedb @lovejoy.zen.co .uk...[color=blue]
      > 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[/color]
      an[color=blue]
      > 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[/color]
      the[color=blue]
      > 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.prin tln("in receive");
      > InputStream in = client.getInput Stream();
      > ObjectInputStre am receive = new ObjectInputStre am(in);
      > Object received = receive.readObj ect();
      > receive.close() ;
      > in.close();
      >
      > Here is the code the server is running to send (it throws the exception[/color]
      just[color=blue]
      > after the println statement):
      >
      > System.out.prin tln("in send");
      > OutputStream out = connection.getO utputStream();
      > System.out.prin tln("got stream one");
      > ObjectOutputStr eam sendStream = new ObjectOutputStr eam(out);
      > sendStream.writ eObject(toSend) ;
      > sendStream.clos e();
      > out.close();
      >
      >[/color]


      Comment

      Working...