Skip to content

Commit 7abfd05

Browse files
author
Kamil Szestowicki
committed
Introduced option to pass to program start configuration.
1 parent 2994aab commit 7abfd05

8 files changed

Lines changed: 339 additions & 276 deletions

File tree

‎README.md‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
SocketTest v3.0.0
1+
SocketTest v3.0.1
22
------------------
33

4-
A java tool for socket testing. It can create both TCP and UDP client or server. It can be used to test any server or client that uses TCP or UDP protocol to communicate.
4+
A java tool for socket testing. It can create both TCP and UDP client or server. It can be used to test any server or client that uses TCP or UDP protocol to communicate.
55

66
Licence: GNU Lesser General Public License
77

@@ -14,3 +14,6 @@ Features:
1414
* TrustManager to prompt if certificate does not get validated.
1515

1616
Copyright © 2003-2008 Akshathkumar Shetty
17+
18+
@Update
19+
* added to program read from command line values

‎dist/SocketTest.jar‎

12.5 KB
Binary file not shown.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package net.sf.sockettest;
2+
3+
public interface NetService {
4+
5+
void setUpConfiguration(String ip, String port);
6+
}
Lines changed: 63 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,110 @@
11
package net.sf.sockettest;
22

33
import java.awt.*;
4-
import java.applet.*;
5-
import java.awt.event.*;
4+
import java.util.HashMap;
5+
import java.util.Map;
66
import javax.swing.*;
7-
import javax.swing.event.*;
8-
import javax.swing.border.*;
7+
98
import net.sf.sockettest.swing.About;
109
import net.sf.sockettest.swing.SocketTestClient;
1110
import net.sf.sockettest.swing.SocketTestServer;
1211
import net.sf.sockettest.swing.SocketTestUdp;
1312
import net.sf.sockettest.swing.SplashScreen;
1413

1514
/**
16-
*
1715
* @author Akshathkumar Shetty
1816
*/
1917
public class SocketTest extends JFrame {
18+
private static final String CLIENT = "c";
19+
private static final String SERVER = "s";
20+
private static final String UDP = "u";
2021
private ClassLoader cl = getClass().getClassLoader();
21-
public ImageIcon logo = new ImageIcon(
22-
cl.getResource("icons/logo.gif"));
23-
public ImageIcon ball = new ImageIcon(
24-
cl.getResource("icons/ball.gif"));
22+
public ImageIcon logo = new ImageIcon(cl.getResource("icons/logo.gif"));
23+
public ImageIcon ball = new ImageIcon(cl.getResource("icons/ball.gif"));
2524
private JTabbedPane tabbedPane;
26-
27-
/** Creates a new instance of SocketTest */
25+
26+
private static Map<String, NetService> services = new HashMap<>();
27+
28+
/**
29+
* Creates a new instance of SocketTest
30+
*/
2831
public SocketTest() {
2932
Container cp = getContentPane();
30-
33+
3134
tabbedPane = new JTabbedPane(JTabbedPane.TOP);
3235
SocketTestClient client = new SocketTestClient(this);
3336
SocketTestServer server = new SocketTestServer(this);
3437
SocketTestUdp udp = new SocketTestUdp(this);
3538
About about = new About();
36-
37-
tabbedPane.addTab("Client", ball, (Component)client, "Test any server");
39+
40+
services.put(CLIENT, client);
41+
services.put(SERVER, server);
42+
services.put(UDP, udp);
43+
44+
tabbedPane.addTab("Client", ball, (Component) client, "Test any server");
3845
tabbedPane.addTab("Server", ball, server, "Test any client");
3946
tabbedPane.addTab("Udp", ball, udp, "Test any UDP Client or Server");
4047
tabbedPane.addTab("About", ball, about, "About SocketTest");
41-
42-
tabbedPane.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
48+
49+
tabbedPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
4350
cp.add(tabbedPane);
4451
}
45-
52+
4653
/**
4754
* @param args the command line arguments
4855
*/
4956
public static void main(String[] args) {
5057
try {
5158
UIManager.setLookAndFeel("net.sourceforge.mlf.metouia.MetouiaLookAndFeel");
52-
} catch(Exception e) {
59+
} catch (Exception e) {
5360
//e.printStackTrace();
5461
try {
5562
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
56-
} catch(Exception ee) {
63+
} catch (Exception ee) {
5764
System.out.println("Error setting native LAF: " + ee);
5865
}
5966
}
60-
61-
boolean toSplash = true;
62-
if(args.length>0) {
63-
if("nosplash".equals(args[0])) toSplash = false;
64-
}
65-
66-
SplashScreen splash = null;
67-
if(toSplash) splash = new SplashScreen();
68-
67+
68+
boolean toSplash = true;
69+
if (args.length > 0) {
70+
if ("nosplash".equals(args[0])) toSplash = false;
71+
}
72+
73+
SplashScreen splash = null;
74+
if (toSplash) splash = new SplashScreen();
75+
6976
SocketTest st = new SocketTest();
70-
st.setTitle("SocketTest v 3.0.0");
71-
st.setSize(600,500);
77+
st.setTitle("SocketTest v 3.0.1");
78+
st.setSize(600, 500);
7279
Util.centerWindow(st);
7380
st.setDefaultCloseOperation(EXIT_ON_CLOSE);
7481
st.setIconImage(st.logo.getImage());
75-
if(toSplash) splash.kill();
82+
83+
setUpArgParams(args);
84+
85+
if (toSplash) splash.kill();
7686
st.setVisible(true);
7787
}
78-
88+
89+
private static void setUpArgParams(String[] configuration) {
90+
if (configuration.length < 1) {
91+
return;
92+
}
93+
94+
//c:ip:port
95+
//s:ip:port
96+
//u:ip:port
97+
for (String arg : configuration) {
98+
String[] params = arg.split(":");
99+
if (params.length == 3) {
100+
String service = params[0];
101+
String ip = params[1];
102+
String port = params[2];
103+
services.get(service).setUpConfiguration(ip, port);
104+
}
105+
}
106+
}
107+
79108
}
109+
110+

0 commit comments

Comments
 (0)