| 1 | import java.io.*; |
| 2 | |
| 3 | |
| 4 | public class Main { |
| 5 | |
| 6 | /** |
| 7 | * main for testing ClientSimplifie |
| 8 | */ |
| 9 | private static void main1() { |
| 10 | ClientSimplifie client = null; |
| 11 | BufferedReader userInput = null; |
| 12 | |
| 13 | try { |
| 14 | client = new ClientSimplifie(); |
| 15 | userInput = new BufferedReader(new InputStreamReader(System.in)); |
| 16 | boolean end = false; |
| 17 | while (!end) { |
| 18 | String line = userInput.readLine(); |
| 19 | if (line.equals(".")) |
| 20 | end = true; |
| 21 | client.sendMsg(line); |
| 22 | String rline = client.receiveMsg(); |
| 23 | System.out.println(rline); |
| 24 | } |
| 25 | } |
| 26 | catch (IOException e) { |
| 27 | System.err.println("IOException: " + e); |
| 28 | } |
| 29 | finally { |
| 30 | client.closeRWIO(); |
| 31 | if (userInput != null) { |
| 32 | try { |
| 33 | userInput.close(); |
| 34 | } |
| 35 | catch (IOException e) { |
| 36 | System.err.println("IOException: " + e); |
| 37 | } |
| 38 | } |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | public static void main (String[] args) { |
| 43 | SocketClient client = null; |
| 44 | Thread thS = null; |
| 45 | Thread thR = null; |
| 46 | |
| 47 | try { |
| 48 | client = new SocketClient(); |
| 49 | thS = new Thread(new ThreadClientSend(client)); |
| 50 | thR = new Thread(new ThreadClientReceive(client)); |
| 51 | thS.setName("thS"); |
| 52 | thS.start(); |
| 53 | thR.setName("thR"); |
| 54 | thR.start(); |
| 55 | } |
| 56 | catch (Exception e) { |
| 57 | System.err.println("Exception: " + e); |
| 58 | } |
| 59 | finally { |
| 60 | try { |
| 61 | thS.join(); |
| 62 | thR.join(); |
| 63 | } |
| 64 | catch (InterruptedException e) { |
| 65 | System.err.println("InterruptedException: " + e); |
| 66 | e.printStackTrace(); |
| 67 | } |
| 68 | client.closeRWIO(); |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | } |