import java.io.*; import java.net.*; import java.util.*; public class KaZaServer implements Runnable { public static final int LISTEN_PORT = 3442; private ServerSocket m_serverSocket; private HashMap m_clientData; public void run() { try { m_serverSocket = new ServerSocket(LISTEN_PORT); /* porcess connection requests */ for (;;) { Socket clientSocket = m_serverSocket.accept(); Thread thread = new Thread(new ClientHandler(clientSocket)); thread.start(); } } catch (IOException ioe) { System.out.println("KaZaServer: IO Exception!"); ioe.printStackTrace(); return; } } public void close() { } public String[] getClientList() { Set s; synchronized (m_clientData) { s = m_clientData.keySet(); } return (String[]) s.toArray(); } private class ClientInfo { String userName; } private class ClientHandler implements Runnable { private Socket m_socket; private String m_clientIP; public ClientHandler(Socket socket) { m_socket = socket; m_clientIP = m_socket.getInetAddress().getHostAddress(); synchronized (m_clientData) { if (!m_clientData.containsKey(m_clientIP)) { m_clientData.put(socket.getInetAddress().getHostAddress(), new ClientInfo()); } } } public void run() { try { BufferedReader br = new BufferedReader( new InputStreamReader( m_socket.getInputStream())); /* loop processing client messages */ for (;;) { String inLine = br.readLine(); StringTokenizer tokens = new StringTokenizer(inLine); if (!tokens.hasMoreTokens()) continue; String opCode = tokens.nextToken(); opCode.toLowerCase(); if (opCode.equals("HELO")) { /* user is announcing his or her username */ } } } catch (Exception e) { } } } }