import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.ServerSocket; import java.net.Socket; /** * @author your name here */ public final class AuthServ implements Runnable { public static final int PORT = 'c' + 'r' + 'a' + 'c' + 'k'; public static void main(String args[]) throws Exception { AuthServ auth = new AuthServ(); auth.run(); } private final ServerSocket listener; private boolean running; public AuthServ() throws IOException { listener = new ServerSocket(PORT); running = false; } public final void run() { running = true; synchronized (this) { while (running) { try { Socket s = listener.accept(); InputStream in = s.getInputStream(); int available = in.available(); if (available != 0) { System.out.println("Client is sending " + available + " bytes."); byte buffer[] = new byte[available]; in.read(buffer, 0, available); String recieved = new String(buffer); // Ignore it, it doesn't really matter as this is infinate. OutputStream out = s.getOutputStream(); // Do the auth routines depending upon if it contains auth1/auth2... Here's auth1 done for you. if(recieved.contains("auth1")) { out.write("your_username: timeleft/".getBytes()); } out.flush(); } s.close(); System.out.println("Cycled."); } catch (IOException e) { e.printStackTrace(); } } } } public final void stop() { synchronized (this) { running = true; } } }