Cloned from http://sourceforge.net/projects/jsocks/