powered by Jive Software

Smack SocketFactories ignoring Java SOCKS proxy settings

Most of the factories did not behave well when Java is configured to use a SOCKS proxy for TCP connections.

See: http://docs.oracle.com/javase/6/docs/technotes/guides/net/properties.html

And also this example:

public static void main(String… args) throws Exception {
// enable Socks proxy for all TCP connections
System.setProperty(“socksProxyHost”, “example.com”);
System.setProperty(“socksProxyPort”, “1080”);

Socket socket = new Socket();
try {

Method m = Socket.class.getDeclaredMethod(“getImpl”);
System.out.println("used socket impl: " + m.invoke(socket).getClass().getName());

Field f = Socket.class.getDeclaredField(“factory”);
System.out.println("used socket factory: " + f.get(null));

socket.bind(new InetSocketAddress((InetAddress) null, 0));
System.out.println("socket bound to: " + socket.getLocalSocketAddress());
socket.connect(new InetSocketAddress(“google.com”, 80));

} finally {


In a standalone application this will mostly not matter because it is unlikely to use this option.

But if you are developing against the Eclipse IDE this will matter because Eclipse will set those

properties if you are adding proxies in the Eclipse configuration.

And this is the part it seems that Smack got wrong:

In the DirectSocketFactory class only 2 of 4 methods are using Proxy.NO_PROXY to bypass the

Java SOCKS proxy.

Furthermore the SOCKS4/5 and HTTP SocketFactory did not even use Proxy.NO_PROXY and so

we are connecting to the SOCKS proxy used by JAVA and afterwards we will connect to the SOCKS

proxy that was passed in in the ConnectionConfiguration class.

It would be really helpful if you offer a way to either completly bypass the JAVA SOCKS5 proxy option or always use

this option for all Smack SocketFactories.