tags:

views:

139

answers:

2

The javadoc for SocketImplFactory specifically mentions that "An application, by changing the socket factory that creates the socket implementation, can configure itself to create sockets appropriate to the local firewall."

However, in order to connect to the firewall in question, one would need a real socket to do the real connection. With the default SocketImplFactory replaced, how does one go about getting a real socket?

I know that java.net.PlainSocketImpl and java.net.SocksSocketImpl are available on Sun's Java, but is there any way to do it in a way that is portable between JVMs?

A: 

You create the socket to connect to the firewall before calling setSocketImplFactory.

Anon.
No good if the socket gets broken or fails to immediately connect.
Tom Hawtin - tackline
That wouldn't work if there needs to be multiple connections to the firewall, as in the case with SOCKS (which needs one TCP connection to the firewall for each tunnelled connection), however.It may be true that one could create a java.net.Socket before setting the factory and then extract the default SocketImpl class from that, and use reflection to instantiate more of them in the future. It would clearly be classified as a hack, but it seems to stand a reasonable chance of being portable between VMs.
+1  A: 

There is some information about the thinking behind this documentation here

Damien B
Thanks, but are you sure that you got the link right? That bug report only relates to DNS name resolution in the context of SocketImpls.
That's the link I was thinking of :-) The discussion shows that's there is no intention to access "real sockets", but to allow to intercept the address to go somewhere else, like through a SOCKS5 proxy. The socks implementation is not in the public API, but java.net.Proxy and java.net.ProxySelector are.
Damien B