+/EE360P

distributed systems

git clone https://git.julia.blue/+/EE360P

vijaygarg1Merge branch 'master' of https://github.com/vijaygarg1/EE-360P04ad5df

master
2.1 KiB56 linesraw
1import java.util.Scanner;
2import java.io.*;
3import java.util.*;
4public class CarClient {
5  public static void main (String[] args) {
6    String hostAddress;
7    int tcpPort;
8    int udpPort;
9    int clientId;
10
11    if (args.length != 2) {
12      System.out.println("ERROR: Provide 2 arguments: commandFile, clientId");
13      System.out.println("\t(1) <command-file>: file with commands to the server");
14      System.out.println("\t(2) client id: an integer between 1..9");
15      System.exit(-1);
16    }
17
18    String commandFile = args[0];
19    clientId = Integer.parseInt(args[1]);
20    hostAddress = "localhost";
21    tcpPort = 7000;// hardcoded -- must match the server's tcp port
22    udpPort = 8000;// hardcoded -- must match the server's udp port
23
24    try {
25        Scanner sc = new Scanner(new FileReader(commandFile));
26
27        while(sc.hasNextLine()) {
28          String cmd = sc.nextLine();
29          String[] tokens = cmd.split(" ");
30
31          if (tokens[0].equals("setmode")) {
32            // TODO: set the mode of communication for sending commands to the server 
33          }
34          else if (tokens[0].equals("rent")) {
35            // TODO: send appropriate command to the server and display the
36            // appropriate responses form the server
37          } else if (tokens[0].equals("return")) {
38            // TODO: send appropriate command to the server and display the
39            // appropriate responses form the server
40          } else if (tokens[0].equals("inventory")) {
41            // TODO: send appropriate command to the server and display the
42            // appropriate responses form the server
43          } else if (tokens[0].equals("list")) {
44            // TODO: send appropriate command to the server and display the
45            // appropriate responses form the server
46          } else if (tokens[0].equals("exit")) {
47            // TODO: send appropriate command to the server 
48          } else {
49            System.out.println("ERROR: No such command");
50          }
51        }
52    } catch (FileNotFoundException e) {
53	e.printStackTrace();
54    }
55  }
56}