1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
   | package client;
 
import java.io.*;
import java.net.*;
import org.omg.PortableInterceptor.DISCARDING;
 
import sy22.coursework.cdtools.*;
 
/**
 *
 * @author MaTT
 */
public class Main {
 
    /** Creates a new instance of Main */
    public Main() {
    }
 
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Socket echoSocket = null;
        PrintWriter out = null;
        BufferedReader in = null;
        Disc disc = null;
        Drive drive = new Drive();
 
        try
        {
            disc = drive.read(); 
            System.out.println(disc.getId());
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
 
        if (disc == null)
        {
            System.out.println("No CD in drive.");
            System.exit(1);
        }
 
        try 
        {
            echoSocket = new Socket("localhost", 4444);
            out = new PrintWriter(echoSocket.getOutputStream(), true);
            in = new BufferedReader(new InputStreamReader(echoSocket.getInputStream()));
        } 
        catch (Exception e)
        {
            System.out.println("Cound not connect to server.");
            e.printStackTrace();
            System.exit(1);
        }
 
        try
        {
            out.println(disc.getId());
 
            String answer = in.readLine();
            System.out.println(answer);
 
            out.close();
            in.close();
            echoSocket.close();
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }
 
} |