• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

returning socket with RMI

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am new to RMI (and java), and am having trouble getting through RemoteException while returning socket from a remote object...
CAN ANYONE PLEASE POINT OUT THE POSSIBLE CAUSE FOR THE EXCEPTION....!!!
The remote object needs to return a socket to the calling client...
The exception is as below:

C:\>java RmiClient
java.rmi.UnmarshalException: error unmarshalling return; nested exception is:
java.io.WriteAbortedException: writing aborted; java.io.NotSerializableE
xception: java.net.Socket
at sun.rmi.server.UnicastRef.invoke(Unknown Source)
at RmiImpl_Stub.getSocket(Unknown Source)
at RmiClient.main(RmiClient.java:12)
Caused by: java.io.WriteAbortedException: writing aborted; java.io.NotSerializab
leException: java.net.Socket
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at sun.rmi.server.UnicastRef.unmarshalValue(Unknown Source)
... 3 more
Caused by: java.io.NotSerializableException: java.net.Socket
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
C:\>java RmiClient
java.rmi.UnmarshalException: error unmarshalling return; nested exception is:
java.io.WriteAbortedException: writing aborted; java.io.NotSerializableE
xception: java.net.Socket
at sun.rmi.server.UnicastRef.invoke(Unknown Source)
at RmiImpl_Stub.getSocket(Unknown Source)
at RmiClient.main(RmiClient.java:12)
Caused by: java.io.WriteAbortedException: writing aborted; java.io.NotSerializab
leException: java.net.Socket
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at sun.rmi.server.UnicastRef.unmarshalValue(Unknown Source)
... 3 more
Caused by: java.io.NotSerializableException: java.net.Socket
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.writeObject(Unknown Source)
at sun.rmi.server.UnicastRef.marshalValue(Unknown Source)
at sun.rmi.server.UnicastServerRef.dispatch(Unknown Source)
at sun.rmi.transport.Transport$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(Unknown Sou
rce)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Sour
ce)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source
)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)


----------------------------
P.S. - Have tried using the returning method locally, and works fine.....so assuming there is no issues on the rmiImplementation side...
 
Sheriff
Posts: 7134
1360
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wonder how to answer this question without having a look at the source code.
And please Tell the details.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The error messages you've got are extremely accurate and descriptive: you can't return a Socket over RMI because Socket isn't serializable. Return values of remote methods must be serializable, because serialization is used to send the object over the wire.

Even aside from that, I'm somewhat surprised that you'd expect this to work in the first place. A socket represents a connection between two processes, often across a network. If you sent one end of a socket from one process to a different one, how would the process at the other end of the socket know which of the two copies of the socket to talk to? Splitting network I/O like this isn't something that's built into any OS I know about.

Anyway, this is an unworkable design -- back to the drawing board!
 
Alas, poor Yorick, he knew this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic