Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Howto send objects between a client and a server

Reply
Thread Tools

Howto send objects between a client and a server

 
 
Brian
Guest
Posts: n/a
 
      10-10-2007

Hi

I'm trying to write a little program that can send an object between a
client and a server - and back. It won't work and I get theese
exceptions:

Server:
java.io.WriteAbortedException: writing aborted;
java.io.NotSerializableException: MyObject

Client:
java.io.NotSerializableException: MyObject

I need a little hint

/Brian





The server:
****************************
ServerSocket ss = new ServerSocket(port);
Socket con = ss.accept();

ObjectInputStream in = new ObjectInputStream(con.getInputStream());
MyObject my = (MyObject) in.readObject();

ObjectOutputStream out = new
ObjectOutputStream(con.getOutputStream());
out.writeObject(my);
out.flush();

con.close();
****************************


The client:
**************************
Socket con = new Socket("localhost", port);

ObjectOutputStream out = new
ObjectOutputStream(con.getOutputStream());
out.writeObject(new MyObject());
out.flush();

ObjectInputStream in = new ObjectInputStream(con.getInputStream());
MyObject my = (MyObject) in.readObject();

System.out.println(my.toString());

con.close();
****************************
 
Reply With Quote
 
 
 
 
Gordon Beaton
Guest
Posts: n/a
 
      10-10-2007
On Wed, 10 Oct 2007 11:13:37 +0200, Brian wrote:
> I'm trying to write a little program that can send an object between a
> client and a server - and back. It won't work and I get theese
> exceptions:
>
> Server:
> java.io.WriteAbortedException: writing aborted;
> java.io.NotSerializableException: MyObject
>
> Client:
> java.io.NotSerializableException: MyObject
>
> I need a little hint


MyObject any other objects it holds (except those marked "transient")
needs to "implements Serializable".

Here's another tip: make a habit of always creating the
ObjectOutputStream *before* the ObjectInputStream. Your server does it
the other way around, and that could come back to bite you one day.

Lots more here:
http://java.sun.com/javase/6/docs/te...ion/index.html

/gordon

--
 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      10-10-2007
On Wed, 10 Oct 2007 11:13:37 +0200, Brian <mail@DEL_oddball_ETE.dk>
wrote, quoted or indirectly quoted someone who said :

>java.io.WriteAbortedException: writing aborted;
>java.io.NotSerializableException: MyObject


see http://mindprod.com/jgloss/serialization.html

Sounds like you are trying to write an object that does not implement
Serializable, or that points (possibly indirectly) to objects (that
will be dragged along with the write) that don't.
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
 
Reply With Quote
 
Brian
Guest
Posts: n/a
 
      10-10-2007
On 10 Oct 2007 10:02:39 GMT, Gordon Beaton <(E-Mail Removed)> wrote:

>
>MyObject any other objects it holds (except those marked "transient")
>needs to "implements Serializable".


Thx
that solved the problem

/Brian
 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      10-11-2007
Brian wrote:
> On 10 Oct 2007 10:02:39 GMT, Gordon Beaton <(E-Mail Removed)> wrote:
>
>> MyObject any other objects it holds (except those marked "transient")
>> needs to "implements Serializable".

>
> Thx [sic]
> that solved the problem


and created new ones.

Simply marking a class Serializable doesn't cover all bases. There's a lot of
work to making a class properly Serializable. Study up on it.

--
Lew
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
question: howto transfer objects between server and client? OpenPavilion Python 3 08-13-2007 03:34 AM
How to send whole file between server's and client's side? schnitzell ASP .Net Web Services 1 08-30-2005 08:19 AM
HOWTO: Send Secure Data To Client Using SSL Dan Sikorsky ASP General 3 10-18-2003 04:46 PM
HowTo Send Uploaded File with INPUT Type file to Sql Server Image Data Type Roberto ASP General 3 10-18-2003 06:56 AM
HowTo:? open email client to send email Peter ASP .Net 0 07-01-2003 04:58 PM



Advertisments