Win a copy of Practice Tests for OCP Java 17 Certification Exam (1Z0-829) this week in the OCPJP forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

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...
 
Bartender
Posts: 1638
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...!!
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...?!


 
author and jackaroo
Posts: 12199
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic