6 public class Main implements Runnable{
\r
7 static private BufferedReader $con = null;
\r
9 static private TCP $tcp = null;
\r
10 static private UDP $udp = null;
\r
12 static public void main(String[] $args)throws Exception{
\r
13 if($args.length != 4){
\r
14 System.out.println("usage: java Server.Main <MyUDPPort> <Server-Addr> <tcpPort> <udpPort>");
\r
17 System.out.println("CLIENT Starting...");
\r
19 $udp = new UDP(Integer.parseInt($args[0]),$args[1],Integer.parseInt($args[3]));
\r
20 System.out.println("CLIENT UDP: "+$args[0]+" <-> "+$args[1]+":"+$args[3]);
\r
22 $tcp = new TCP($args[1],Integer.parseInt($args[2]));
\r
23 System.out.println("CLIENT TCP: "+$args[0]);
\r
25 new Thread(new Main()).start();
\r
26 System.out.println("CLIENT IDLE.");
\r
31 Thread.currentThread().setPriority(9);
\r
32 $con = new BufferedReader (new InputStreamReader(System.in));
\r
33 while($con != null)try{auswertung($con.readLine().trim());}catch(Exception $e){$e.printStackTrace();} //Eingaben auswerten
\r
34 }catch(Exception $e){$e.printStackTrace();}
\r
38 static public void auswertung(String $eingraw)throws Exception{
\r
39 if($eingraw.equals("") || $eingraw == null)return; // Ignore null-commands
\r
40 String[] $eing = $eingraw.split("\\s+"); //regex: whitespace character once and more
\r
42 if($eing[0].equalsIgnoreCase("!end")){
\r
43 $tcp.send("!logout");
\r
50 if($eing[0].equalsIgnoreCase("!list")){$udp.send($eingraw); return;}
\r
51 if($eing[0].equalsIgnoreCase("!info")){$udp.send($eingraw); return;}
\r
52 if($eing[0].charAt(0) == '!'){$tcp.send($eingraw); return;}
\r
53 System.out.println("Unknown input: "+$eingraw);
\r