• Post Reply Bookmark Topic Watch Topic
  • New Topic

returning socket with RMI

 
Sagar Patel
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • 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...
 
Devaka Cooray
Marshal
Posts: 5158
481
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • Mark post as helpful
  • send pies
  • 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.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24213
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • 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!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!