public class TCPFIN extends base{ final int FIN_WAIT_1 = 1; final int FIN_WAIT_2 = 2; final int CLOSING = 3; final int TIME_WAIT = 4; final int CLOSED = 5; int state; //Ich haette das hier gleich mit FIN_WAIT_1 initialisiert. void close() throws IOException{ state = FIN_WAIT_1; send(FIN); } void receive(int flag) throws IOException{ if(flag == FIN){ if(state == FIN_WAIT_1){ state = CLOSING; } else if(state == FIN_WAIT_2){ state = TIME_WAIT; startTimer(); } send(ACK); } else if(flag == ACK){ if(state == FIN_WAIT_1){ state = FIN_WAIT_2; } else if(state == CLOSING){ state = TIME_WAIT; startTimer(); } } } void timeout() throws WrongStateException{ if(state != TIME_WAIT){ throw new WrongStateException(); } state = CLOSED; } }