ServerThread.java 913 Bytes
Newer Older
Michele Fiori's avatar
Michele Fiori committed
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
package theatre;

import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;

public class ServerThread extends Thread {
    private Socket connectionSocket = null;
    private Reservations reservations;
    private DataOutputStream outToClient;

    // the constructor argument is an established socket
    public ServerThread(Socket s, Reservations reservations) {
        this.reservations = reservations;
        connectionSocket = s;
        try {
            outToClient = new DataOutputStream(connectionSocket.getOutputStream());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public void run() {
        try {
            outToClient.writeBytes(this.reservations.buyTicket() + "\n");
            connectionSocket.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}