-
Notifications
You must be signed in to change notification settings - Fork 58
Home
terma edited this page Sep 2, 2012
·
11 revisions
Info: TCP Proxy doesn't need any external jars only JRE =)
Create configuration file proxy.config:
# example config for tcp proxy
proxy1.localPort = 8000
proxy1.remoteHost = my.server
proxy1.remotePort = 80
Run proxy with configuration file in parameter:
java -jar javaniotcpproxy-1.2-SNAPSHOT.jar proxy.config
Note: Current implementation tries to use all available processors, so if you setup 2 proxy and your machine has 4 cores, proxy will start 2 workers per instance for avoid context switching. In any cases if you have only 2 cores and setup 4 instances proxy will start 1 worker per instance.
Just add settings for new proxy to your config file:
# first instance
proxy1.localPort = 8000
proxy1.remoteHost = my.server
proxy1.remotePort = 80
# second instance
proxy2.localPort = 9000
proxy2.remoteHost = second.server
proxy2.remotePort = 8080
Add to your pom, maven artifact:
<dependency>
<groupId>com.github.terma</groupId>
<artifactId>javaniotcpproxy</artifactId>
<version>1.1</version>
</dependency>
Create and configure proxy:
// create config for proxy
TcpProxyConfig config = new TcpProxyConfig(localPort, remoteHost, remotePort);
config.setWorkerCount(workerCount);
// init proxy
TcpProxy proxy = new TcpProxy(config);
// start proxy
proxy.start();
// stop proxy
proxy.shutdown();
Start is not blocking method, so when proxy server started it return control.