Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

returning socket with RMI  RSS feed

 
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...
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All arguments and the return type of a remote method must be serializable. In your case it is not, that is the reason of the exception.
 
Sagar Patel
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply....

Is there any way around this limitation...
Can i pass a socket by any way.....!!
All i require of the Remote object is passing a reference of one of three server which is running...
I am willing to employ fault-tolerant server model...
Either this way or other, can anyone please suggest a way around...!!
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't pass a socket, which is tied to the originating operating system, instead pass the IP address and socket number which your other applications can use to address the socket.

Bill
 
Sagar Patel
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well if thats the only fallback so be it...!!
Cheers guys for prompt replies...!!
 
Sagar Patel
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fallen into another problem...
Its with initializing InetAddress......
Am willing to initialize an array of InetAddress in the class declaration....

As Expected the following code gives a an unhandled UnknownHostException, however, i cannot surround it with try/catch as its in the class declaration...Where am i goofing up...?!


 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Posts: 12090
246
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"java Greenhorn"

Please check your private messages regarding an important administrative matter.

-Andrew
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java Greenhorn wrote:Fallen into another problem...
Its with initializing InetAddress......
Am willing to initialize an array of InetAddress in the class declaration....

As Expected the following code gives a an unhandled UnknownHostException, however, i cannot surround it with try/catch as its in the class declaration...Where am i goofing up...?!




This is not related to the original problem you had. UseOneThreadPerQuestion, you can start a new topic in Java In General forum.

Please do look into your PM as Andrew has pointed out.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!