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

public class SocketPortListen extends Thread{
	
	private ServerGUI serverGUI;
	private int startPort;
	private int size;
	
	public void setViewPort(ServerGUI serverGUI) {
		this.serverGUI = serverGUI;
	}

	public SocketPortListen() {
		this(10240);
	}
	
	public SocketPortListen(int startPort) {
		this.startPort = startPort;
		this.size = 300;
		start();
	}
	
	public void setPacketSize(int size) {
		this.size = size;
	}
	
	@Override
	public void run() {
		try {
			@SuppressWarnings("resource")
			ServerSocket server = new ServerSocket(startPort);
			while(true) {
				Socket client = server.accept();
				UrlSendThread urlSendThread = new UrlSendThread(client);
				urlSendThread.setViewport(serverGUI);
				urlSendThread.setUrlPacketSize(size);
				urlSendThread.start();
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
