Skip to content

Commit d529d1f

Browse files
authored
Merge pull request google#34 from google/add-persistent-dir
Adding a path for persistent data
2 parents d1353fb + a128034 commit d529d1f

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ JAVA 7 when working with this project.
3737
the following two commands in separate shells:
3838

3939
```
40-
$ sh run_server.sh <team_id> <team_secret> <port>
40+
$ sh run_server.sh <team_id> <team_secret> <port> <persistent-dir>
4141
$ sh run_client.sh <host> <port>
4242
```
4343

@@ -58,6 +58,8 @@ JAVA&nbsp;7 when working with this project.
5858
```
5959
6060
if the port is already in use.
61+
+ `<persistent-dir>`: the path where you want the server to save data between
62+
runs.
6163
6264
The startup arguments for `run_client.sh` are the following:
6365
+ `<host>`: the hostname or IP address of the computer on which the server

run_server.sh

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,41 @@
1717
TEAM_ID="$1"
1818
TEAM_SECRET="$2"
1919
PORT="$3"
20-
RELAY_ADDRESS="$4"
20+
PERSISTENT_DIR="$4"
21+
RELAY_ADDRESS="$5"
2122

22-
if [[ "TEAM_ID" == "" || "$TEAM_SECRET" == "" || "$PORT" == "" ]] ; then
23-
echo 'usage: <TEAM ID> <TEAM SECRET> <PORT> [RELAY ADDRESS]'
23+
if [[ "$TEAM_ID" == "" || "$TEAM_SECRET" == "" || "$PORT" == "" || "$PERSISTENT_DIR" == "" ]] ; then
24+
echo 'usage: <TEAM ID> <TEAM SECRET> <PORT> <PERSISTENT> [RELAY ADDRESS]'
25+
echo ''
26+
echo 'TEAM ID : The id registered with the relay server. If you are'
27+
echo ' not connecting to a relay server, use "100".'
28+
echo 'TEAM SECRET : The secret registerd with the relay server. If you are'
29+
echo ' not connecting to a relay server, use "ABABAB".'
30+
echo 'PORT : The port that the server will listen to for incoming '
31+
echo ' connections. This can be anything from 1024 to 65535.'
32+
echo 'PERSISTENT DIR : The directory where the server can save data that will'
33+
echo ' exists between runs.'
34+
echo 'RELAY ADDRESS : This value is optional. If you want to connect to a '
35+
echo ' relay server, the address must be IP@PORT where IP is'
36+
echo ' the ip address of the relay server and PORT is the port'
37+
echo ' the relay server is listing on.'
38+
echo ''
2439
exit 1
2540
fi
2641

42+
2743
cd './bin'
2844
if [ "$RELAY_ADDRESS" == "" ] ; then
2945
java codeu.chat.ServerMain \
3046
"$TEAM_ID" \
3147
"$TEAM_SECRET" \
32-
"$PORT"
48+
"$PORT" \
49+
"$PERSISTENT_DIR"
3350
else
3451
java codeu.chat.ServerMain \
3552
"$TEAM_ID" \
3653
"$TEAM_SECRET" \
3754
"$PORT" \
55+
"$PERSISTENT_DIR" \
3856
"$RELAY_ADDRESS"
3957
fi

src/codeu/chat/ServerMain.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,12 @@ public static void main(String[] args) {
5151

5252
final int myPort = Integer.parseInt(args[2]);
5353

54-
final RemoteAddress relayAddress = args.length > 3 ?
55-
RemoteAddress.parse(args[3]) :
54+
// This is the directory where it is safe to store data accross runs
55+
// of the server.
56+
final String persistentPath = args[3];
57+
58+
final RemoteAddress relayAddress = args.length > 4 ?
59+
RemoteAddress.parse(args[4]) :
5660
null;
5761

5862
try (

0 commit comments

Comments
 (0)