package network.server;

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

public class ServerAcceptThread extends Thread {

	private final Server server;

	public ServerAcceptThread(Server server) {
		this.server = server;
	}

	public void cancel() {
		try {
			this.server.serverSocket.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		interrupt();
	}

	@Override
	public void run() {
		try {
			while(!interrupted()) {
				Socket newConnection = this.server.serverSocket.accept();
				ServerConnexion serverConnection = new ServerConnexion(newConnection, this.server);
				this.server.connexions.add(serverConnection);
			}
		} catch(IOException e) {
			// e.printStackTrace();
		}
	}

}
