socks
Class ProxyServer

java.lang.Object
  |
  +--socks.ProxyServer

public class ProxyServer
extends java.lang.Object
implements java.lang.Runnable

SOCKS4 and SOCKS5 proxy, handles both protocols simultaniously. Implements all SOCKS commands, including UDP relaying.

In order to use it you will need to implement ServerAuthenticator interface. There is an implementation of this interface which does no authentication ServerAuthenticatorNone, but it is very dangerous to use, as it will give access to your local network to anybody in the world. One should never use this authentication scheme unless one have pretty good reason to do so. There is a couple of other authentication schemes in socks.server package.

See Also:
ServerAuthenticator

Constructor Summary
ProxyServer(ServerAuthenticator auth)
          Creates a proxy server with given Authentication scheme.
 
Method Summary
static Proxy getProxy()
          Get proxy.
 void run()
           
static void setAcceptTimeout(int timeout)
          Sets the timeout for BIND command, how long the server should wait for the incoming connection.
Zero timeout implies infinity.
Default timeout is 3 minutes.
static void setDatagramSize(int size)
          Sets the size of the datagrams used in the UDPRelayServer.
Default size is 64K, a bit more than maximum possible size of the datagram.
static void setIddleTimeout(int timeout)
          Sets the timeout for connections, how long shoud server wait for data to arrive before dropping the connection.
Zero timeout implies infinity.
Default timeout is 3 minutes.
static void setLog(java.io.OutputStream out)
          Set the logging stream.
static void setProxy(Proxy p)
          Set proxy.
static void setUDPTimeout(int timeout)
          Sets the timeout for UDPRelay server.
Zero timeout implies infinity.
Default timeout is 3 minutes.
 void start(int port)
          Start the Proxy server at given port.
This methods blocks.
 void start(int port, int backlog, java.net.InetAddress localIP)
          Create a server with the specified port, listen backlog, and local IP address to bind to.
 void stop()
          Stop server operation.It would be wise to interrupt thread running the server afterwards.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ProxyServer

public ProxyServer(ServerAuthenticator auth)
Creates a proxy server with given Authentication scheme.
Parameters:
auth - Authentication scheme to be used.
Method Detail

setLog

public static void setLog(java.io.OutputStream out)
Set the logging stream. Specifying null disables logging.

setProxy

public static void setProxy(Proxy p)
Set proxy.

Allows Proxy chaining so that one Proxy server is connected to another and so on. If proxy supports SOCKSv4, then only some SOCKSv5 requests can be handled, UDP would not work, however CONNECT and BIND will be translated.

Parameters:
p - Proxy which should be used to handle user requests.

getProxy

public static Proxy getProxy()
Get proxy.
Returns:
Proxy wich is used to handle user requests.

setIddleTimeout

public static void setIddleTimeout(int timeout)
Sets the timeout for connections, how long shoud server wait for data to arrive before dropping the connection.
Zero timeout implies infinity.
Default timeout is 3 minutes.

setAcceptTimeout

public static void setAcceptTimeout(int timeout)
Sets the timeout for BIND command, how long the server should wait for the incoming connection.
Zero timeout implies infinity.
Default timeout is 3 minutes.

setUDPTimeout

public static void setUDPTimeout(int timeout)
Sets the timeout for UDPRelay server.
Zero timeout implies infinity.
Default timeout is 3 minutes.

setDatagramSize

public static void setDatagramSize(int size)
Sets the size of the datagrams used in the UDPRelayServer.
Default size is 64K, a bit more than maximum possible size of the datagram.

start

public void start(int port)
Start the Proxy server at given port.
This methods blocks.

start

public void start(int port,
                  int backlog,
                  java.net.InetAddress localIP)
Create a server with the specified port, listen backlog, and local IP address to bind to. The localIP argument can be used on a multi-homed host for a ServerSocket that will only accept connect requests to one of its addresses. If localIP is null, it will default accepting connections on any/all local addresses. The port must be between 0 and 65535, inclusive.
This methods blocks.

stop

public void stop()
Stop server operation.It would be wise to interrupt thread running the server afterwards.

run

public void run()
Specified by:
run in interface java.lang.Runnable