Skip to content

Commit 89fb07c

Browse files
author
Jose Damico
committed
Added command line parameters support.
1 parent ccb473e commit 89fb07c

File tree

4 files changed

+25
-8
lines changed

4 files changed

+25
-8
lines changed
Binary file not shown.

java-socks-proxy-server/src/org/jdamico/socks/server/StartProxy.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,30 @@
77

88
public class StartProxy {
99

10-
public static boolean enableLog = false;
10+
public static boolean enableDebugLog = false;
1111
public static void main(String[] args) {
1212

13+
/*
14+
* enableDebugLog
15+
* listenPort
16+
*/
1317

14-
enableLog = true;
18+
int port = Constants.LISTEN_PORT;
1519

16-
new ProxyServerInitiator(Constants.LISTEN_PORT, Constants.PROXY_HOST, Constants.PROXY_PORT ).start();
20+
String noParamsMsg = "Unable to parse command-line parameters, using default configuration.";
21+
22+
if(args.length == 2){
23+
try {
24+
String prePort = args[0].trim();
25+
port = Integer.parseInt(prePort);
26+
String preDebug = args[1].trim();
27+
enableDebugLog = Boolean.parseBoolean(preDebug);
28+
} catch (Exception e) {
29+
System.out.println(noParamsMsg);
30+
}
31+
}else System.out.println(noParamsMsg);
32+
33+
new ProxyServerInitiator(port).start();
1734
}
1835

1936
}

java-socks-proxy-server/src/org/jdamico/socks/server/commons/DebugLog.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,26 @@ public static DebugLog getInstance(){
2424

2525

2626
public void println( String txt ) {
27-
if( StartProxy.enableLog ) print( txt + Constants.EOL );
27+
if( StartProxy.enableDebugLog ) print( txt + Constants.EOL );
2828
}
2929

3030

3131
public void print( String txt ) {
32-
if( !StartProxy.enableLog ) return;
32+
if( !StartProxy.enableDebugLog ) return;
3333
if( txt == null ) return;
3434
System.out.print( txt );
3535
}
3636

3737
/////////////////////////////////////////////////
3838

3939
public void error( String txt ) {
40-
if( StartProxy.enableLog ) println( "Error : " + txt );
40+
if( StartProxy.enableDebugLog ) println( "Error : " + txt );
4141
}
4242

4343
/////////////////////////////////////////////////
4444

4545
public void error( Exception e ) {
46-
if( !StartProxy.enableLog ) return;
46+
if( !StartProxy.enableDebugLog ) return;
4747
println( "ERROR : " + e.toString() );
4848
e.printStackTrace();
4949
}

java-socks-proxy-server/src/org/jdamico/socks/server/impl/ProxyServerInitiator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class ProxyServerInitiator implements Runnable
2828

2929
public int getPort() { return m_nPort; }
3030

31-
public ProxyServerInitiator(int listenPort, String proxyHost, int proxyPort) {
31+
public ProxyServerInitiator(int listenPort) {
3232

3333
m_lock = this;
3434
m_nPort = listenPort;

0 commit comments

Comments
 (0)