Forum Stats

  • 3,757,146 Users
  • 2,251,201 Discussions


Too many sockets with custom socket factory implementation with JSSE

User_I9M6G Member Posts: 1 Red Ribbon


I've implemented custom socket factory as defined in the JSSE example here:

When I run my applications, rmi works fine along with ssl. But, what I noticed is that too many threads/ sockets are created. Socket reuse is not happening. When looking for this problem, found out this page: (look for A.5), which expresses the problem with too many socket creation when using custom socket factories. When tried to override the equal and hashcode of custom socket factories, the looking up of remote object in the registry fails during unmarshalling phase. It throws an exception about the serialVersionUID of the custom client socket factory being different from the local class as below.

java.rmi.UnmarshalException: error unmarshalling return; nested exception is: ...SslClientSocketFactory; local class incompatible: stream classdesc serialVersionUID = -2466850771396148787, local class serialVersionUID = -8809708706764478887

Defining a static serialVersionUID for SslClientSocketFactory also doesn't work. Throws the same exception. The problem can be that RMI runtime internally uses RMIClientSocketFactory for getting the rmi clients for RMI calls and has a different serialVersionUID for the client socket factory.

Has anyone faced a similar problem and have a solution for this?