Code example for ServerSocket

Methods: accept, close

0
    public static int CURRENT_THREADS = 0;
    private ServerSocket server;
    public ServerDaemon() { 
        System.out.println("Server start...");
        try { 
            server = new ServerSocket(PORT);
            if(CURRENT_THREADS < MAX_THREADS) {
                ServerThread thread = new ServerThread(server.accept());
                thread.start();
            } 
        } catch(Exception ex) {
            ex.printStackTrace();
        } finally { 
            try { 
                server.close();
            } catch(Exception ex) {
                ex.printStackTrace();
            } 
        } 
    }