package kamiworldserver.control;

import kamiworldserver.KamiServer;

import java.net.*;
import java.io.IOException;

public class KamiListener extends Thread {

    ServerSocket ss_Socket;
    Socket s_Socket;
    int nPort = 0;

    public KamiListener(int port) {
        nPort = port;
    }

    @Override
    public void run() {

        try {
            ss_Socket = new ServerSocket(nPort);
            System.out.println("Server listener: Accepting.");
            while (true) {
                s_Socket = ss_Socket.accept();
                System.out.println("Server listener: Socket accepted - adding.");
                KamiServer.addUser(s_Socket);
                //s_Socket.setTcpNoDelay(false);
                System.out.println("Server listener: New user connected.");
            }
        } catch (IOException e) {
            System.out.println("Accept failed: 31338");
            System.exit(-1);
        }
    }
}