+/EE360P
distributed systems
git clone https://git.julia.blue/+/EE360P
99f4f39
master
1package name ; 2import java .net .*;import java .io .*;import java .util .*; 3public class ServerThread extends Thread { 4NameTable table ; 5Socket theClient ; 6public ServerThread (NameTable table ,Socket s ) { 7this .table =table ; 8theClient =s ; 9 } 10public void run () { 11try { 12Scanner sc =new Scanner (theClient .getInputStream ()); 13PrintWriter pout =new PrintWriter (theClient .getOutputStream ()); 14String command =sc .nextLine (); 15System .out .println ("received:" +command ); 16Scanner st =new Scanner (command ); 17String tag =st .next (); 18if (tag .equals ("search" )) { 19InetSocketAddress addr =table .search (st .next ()); 20if (addr ==null )pout .println (0 +" " +"nullhost" ); 21else pout .println (addr .getPort () +" " +addr .getHostName ()); 22 }else if (tag .equals ("insert" )) { 23String name =st .next (); 24String hostName =st .next (); 25int port =st .nextInt (); 26int retValue =table .insert (name ,hostName ,port ); 27pout .println (retValue ); 28 }else if (tag .equals ("blockingFind" )) { 29InetSocketAddress addr =table .blockingFind (st .next ()); 30pout .println (addr .getPort () +" " +addr .getHostName ()); 31 }else if (tag .equals ("clear" )) { 32table .clear (); 33 } 34pout .flush (); 35theClient .close (); 36 }catch (IOException e ) { 37System .err .println (e ); 38 } 39 40 } 41} 42