Skip to content

Commit 2ca6d17

Browse files
committed
The location of the server can now be passed by command line
1 parent fdc1bd5 commit 2ca6d17

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

‎example/ChatClient.java‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class ChatClient extends JFrame implements ActionListener {
3434
private final JComboBox draft;
3535
private WebSocketClient cc;
3636

37-
public ChatClient() {
37+
public ChatClient( String defaultlocation ) {
3838
super("WebSocket Chat Client");
3939
Container c = getContentPane();
4040
GridLayout layout = new GridLayout();
@@ -47,7 +47,7 @@ public ChatClient() {
4747
c.add(draft);
4848

4949
uriField = new JTextField();
50-
uriField.setText("ws://localhost:8887");
50+
uriField.setText( defaultlocation );
5151
c.add(uriField);
5252

5353
connect = new JButton("Connect");
@@ -156,7 +156,16 @@ public void onIOError(IOException ex) {
156156
}
157157

158158
public static void main(String[] args) {
159-
new ChatClient();
159+
String location;
160+
if( args.length != 0 ){
161+
location = args[0];
162+
System.out.println( "Default server url specified: \'" + location + "\'" );
163+
}
164+
else{
165+
location = "ws://localhost:8887";
166+
System.out.println( "Default server url not specified: defaulting to \'" + location + "\'" );
167+
}
168+
new ChatClient( location );
160169
}
161170

162171
}

0 commit comments

Comments
 (0)