public class GenericSocksProxyServer extends Object implements SocksProxyServer, Runnable
GenericSocksProxyServer
is a implementation of SocksProxyServer
.ProxyServer proxyServer = new GenericSocksProxyServer(Socks5Handler.class); proxyServer.start(); // Create a SOCKS5 server bind at 1080.If you want change the port, you can using following codes:
proxyServer.start(9999);
Modifier and Type | Field and Description |
---|---|
protected static org.slf4j.Logger |
logger |
protected static int |
THREAD_NUMBER
Number of threads in thread pool.
|
DEFAULT_SOCKS_PORT
Constructor and Description |
---|
GenericSocksProxyServer(Class<? extends SocksHandler> socketHandlerClass)
Constructs a
GenericSocksProxyServer by a SocksHandler class. |
GenericSocksProxyServer(Class<? extends SocksHandler> socketHandlerClass,
ExecutorService executorService)
Constructs a
GenericSocksProxyServer by a SocksHandler class and a
ExecutorService. |
GenericSocksProxyServer(Class<? extends SocksHandler> socketHandlerClass,
int port)
Constructs a
GenericSocksProxyServer by a SocksHandler class and a port. |
GenericSocksProxyServer(Class<? extends SocksHandler> socketHandlerClass,
int port,
ExecutorService executorService)
Constructs a
GenericSocksProxyServer by a SocksHandler class , a port and a
ExecutorService. |
Modifier and Type | Method and Description |
---|---|
void |
addSessionFilter(SessionFilter sessionFilter)
Adds
SessionFilter . |
void |
addSocksCommandFilter(SocksCommandFilter socksListener)
Adds a
SocksCommandFilter . |
protected void |
closeAllSession()
Closes all sessions.
|
protected ServerSocket |
createServerSocket(int bindPort) |
SocksHandler |
createSocksHandler()
Create an instance
SocksHandler . |
int |
getBindPort() |
int |
getBufferSize()
Returns buffer size.
|
ExecutorService |
getExecutorService() |
Map<Long,Session> |
getManagedSessions()
Gets all sessions that SOKCS server managed.
|
SocksProxy |
getProxy() |
SessionFilterChain |
getSessionFilterChain() |
int |
getTimeout()
Returns timeout.
|
void |
initializeSocksHandler(SocksHandler socksHandler)
Initializes
SocksHandler . |
void |
removeSessionFilter(SessionFilter sessionFilter)
Removes
SessionFilter . |
void |
removeSocksCommandFilter(SocksCommandFilter socksListener)
Removes a
SocksCommandFilter . |
void |
run() |
void |
setBindPort(int bindPort) |
void |
setBufferSize(int bufferSize)
Sets buffer size.
|
void |
setExecutorService(ExecutorService executorService) |
void |
setProxy(SocksProxy proxy) |
void |
setSessionFilterChain(SessionFilterChain sessionFilterChain) |
void |
setSupportMethods(SocksMethod... methods)
Sets the methods that socks server supports.
|
void |
setTimeout(int timeout)
Sets timeout.
|
void |
shutdown()
Shutdown a SOCKS server.
|
void |
start()
Starts a SOCKS server.
|
void |
start(int bindPort)
Starts a SOCKS server and binds a port.
|
protected static final org.slf4j.Logger logger
protected static final int THREAD_NUMBER
public GenericSocksProxyServer(Class<? extends SocksHandler> socketHandlerClass)
GenericSocksProxyServer
by a SocksHandler
class. The bind port is
1080.socketHandlerClass
- SocksHandler
class.public GenericSocksProxyServer(Class<? extends SocksHandler> socketHandlerClass, int port)
GenericSocksProxyServer
by a SocksHandler
class and a port.socketHandlerClass
- SocksHandler
class.port
- The port that SOCKS server will listen.public GenericSocksProxyServer(Class<? extends SocksHandler> socketHandlerClass, ExecutorService executorService)
GenericSocksProxyServer
by a SocksHandler
class and a
ExecutorService.socketHandlerClass
- SocksHandler
class.executorService
- Thread pool.public GenericSocksProxyServer(Class<? extends SocksHandler> socketHandlerClass, int port, ExecutorService executorService)
GenericSocksProxyServer
by a SocksHandler
class , a port and a
ExecutorService.socketHandlerClass
- SocksHandler
class.port
- The port that SOCKS server will listen.executorService
- Thread pool.public void setExecutorService(ExecutorService executorService)
public void shutdown()
SocksProxyServer
shutdown
in interface SocksProxyServer
public void start() throws IOException
SocksProxyServer
start
in interface SocksProxyServer
IOException
- If any I/O error occurs.public void start(int bindPort) throws IOException
SocksProxyServer
start
in interface SocksProxyServer
bindPort
- The port that SOCKS server listened..IOException
- If any I/O error occurs.protected ServerSocket createServerSocket(int bindPort) throws IOException
IOException
public SocksHandler createSocksHandler()
SocksProxyServer
SocksHandler
.createSocksHandler
in interface SocksProxyServer
SocksHandler
.public void initializeSocksHandler(SocksHandler socksHandler)
SocksProxyServer
SocksHandler
.initializeSocksHandler
in interface SocksProxyServer
socksHandler
- The instance of SocksHandler
.protected void closeAllSession()
public ExecutorService getExecutorService()
public Map<Long,Session> getManagedSessions()
SocksProxyServer
getManagedSessions
in interface SocksProxyServer
public void setSupportMethods(SocksMethod... methods)
SocksProxyServer
setSupportMethods
in interface SocksProxyServer
methods
- The methods that SOCKS server sports.public int getTimeout()
SocksProxyServer
getTimeout
in interface SocksProxyServer
public void setTimeout(int timeout)
SocksProxyServer
setTimeout
in interface SocksProxyServer
timeout
- timeout.public int getBufferSize()
SocksProxyServer
getBufferSize
in interface SocksProxyServer
public void setBufferSize(int bufferSize)
SocksProxyServer
setBufferSize
in interface SocksProxyServer
bufferSize
- Buffer size.public void addSocksCommandFilter(SocksCommandFilter socksListener)
SocksProxyServer
SocksCommandFilter
.addSocksCommandFilter
in interface SocksProxyServer
socksListener
- Instance of SocksCommandFilter
.public void removeSocksCommandFilter(SocksCommandFilter socksListener)
SocksProxyServer
SocksCommandFilter
.removeSocksCommandFilter
in interface SocksProxyServer
socksListener
- Instance of SocksCommandFilter
.public void addSessionFilter(SessionFilter sessionFilter)
SocksProxyServer
SessionFilter
.addSessionFilter
in interface SocksProxyServer
sessionFilter
- Instance of SessionFilter
.public void removeSessionFilter(SessionFilter sessionFilter)
SocksProxyServer
SessionFilter
.removeSessionFilter
in interface SocksProxyServer
sessionFilter
- Instance of SessionFilter
.public SocksProxy getProxy()
getProxy
in interface SocksProxyServer
public void setProxy(SocksProxy proxy)
setProxy
in interface SocksProxyServer
public int getBindPort()
getBindPort
in interface SocksProxyServer
public void setBindPort(int bindPort)
setBindPort
in interface SocksProxyServer
public SessionFilterChain getSessionFilterChain()
public void setSessionFilterChain(SessionFilterChain sessionFilterChain)
Copyright © 2015. All rights reserved.