+/EE360P
distributed systems
git clone https://git.julia.blue/+/EE360P
04ad5df
master
1import java .util .Scanner ; 2import java .io .*; 3import java .util .*; 4public class CarClient { 5public static void main (String []args ) { 6String hostAddress ; 7int tcpPort ; 8int udpPort ; 9int clientId ; 10 11if (args .length !=2 ) { 12System .out .println ("ERROR: Provide 2 arguments: commandFile, clientId" ); 13System .out .println ("\t(1) <command-file>: file with commands to the server" ); 14System .out .println ("\t(2) client id: an integer between 1..9" ); 15System .exit (-1 ); 16 } 17 18String commandFile =args [0 ]; 19clientId =Integer .parseInt (args [1 ]); 20hostAddress ="localhost" ; 21tcpPort =7000 ;// hardcoded -- must match the server's tcp port 22udpPort =8000 ;// hardcoded -- must match the server's udp port 23 24try { 25Scanner sc =new Scanner (new FileReader (commandFile )); 26 27while (sc .hasNextLine ()) { 28String cmd =sc .nextLine (); 29String []tokens =cmd .split (" " ); 30 31if (tokens [0 ].equals ("setmode" )) { 32// TODO: set the mode of communication for sending commands to the server 33 } 34else 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 { 49System .out .println ("ERROR: No such command" ); 50 } 51 } 52 }catch (FileNotFoundException e ) { 53e .printStackTrace (); 54 } 55 } 56}