How to use SocketImplFactory to manipulate sockets in whole application?
posted 6 years ago
I need your kind advice here.
What I need is basically for every socket in my application ( that doesnt deal directly with Sockets ) to have TCP_NODELAY set to true.
I consulted JDK javadocs regarding static Socket.setSocketImplFactory(...) method and java.net.SocketImplFactory interface in hopes of implementing it to create some standard SocketImpl`s for me and calling .setOption( java.net.SocketOptions.TCP_NO_DELAY , ... ) on them, but there seems not to be any publicly available SocketImpl implementations for that. Closest is java.net.SocksSocketImpl, but I obviously cant subclass that since it has default access in the package. I read somewhere that reflection could be used to subclass a class with default access, but I`d rather not get into that mess.
Another interesting class is javax.net.SocketFactory, that I could subclass, override abstract methods by calling super and setting desired option with .setTcpNoDelay(true) on created sockets, but I failed to find any way to set my subclass into the system so it gets used instead of the default one.
I`m at a loss. Could anyone please provide any insight?