package network;

import java.io.IOException;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;

public class TCPServer extends Thread{
	
	private ServerSocket socket;
	private InetAddress address;
	private int port;
	private ArrayList<TCPChat> listeConnexions;
	
	public TCPServer(int port, InetAddress address) throws IOException {
		this.socket = new ServerSocket(port, 1000, address);
		this.address = address;
		this.port = port;
		this.listeConnexions = new ArrayList<TCPChat>();
		this.start();
	}
	
	@Override
	public void run() {
		Socket link;
		try {
			link = socket.accept();
			this.listeConnexions.add(new TCPChat(link));
			//link.close();// A APPELER QUELQUE PART D'AUTRE
		} catch (IOException e) {
			System.out.println("Socket non créé ou non fermé");
			e.printStackTrace();
		}
		
	}

	public InetAddress getAddress() {
		return address;
	}

	public void setAddress(InetAddress address) {
		this.address = address;
	}
}
