import java.io.*; import java.net.*; import java.util.*; public class Randserv{ static Vector kasutajad=new Vector(); static Date algaeg=new Date(); public static void main(String argumendid[]) throws IOException{ ServerSocket ss=new ServerSocket(3001); while(true){ kasutajad.add(new Loim(ss.accept())); // String IP = Socket.getRemoteSocketAddress().toString(); } } public synchronized static void kirjutalog(int teade){ try{ PrintWriter faili=new PrintWriter(new FileWriter("minulog.txt",true)); faili.println(new Date()+ " "+teade); faili.close(); }catch(Exception ex){ex.printStackTrace();} } /*public synchronized static void trykilog(PrintWriter sihtkoht){ try{ BufferedReader failist= new BufferedReader(new FileReader("minulog.txt")); for(String rida=failist.readLine(); rida!=null;rida=failist.readLine()){ sihtkoht.println(rida); } failist.close(); }catch(Exception ex){ex.printStackTrace();} }*/ public synchronized static void analyze(PrintWriter sihtkoht){ try{ BufferedReader failist= new BufferedReader(new FileReader("minulog.txt")); int loendur=0; String rida=failist.readLine(); while(rida!=null){ loendur++; rida=failist.readLine(); } //System.out.println(loendur); sihtkoht.println(loendur); failist.close(); }catch(Exception ex){ ex.printStackTrace(); } } static class Loim extends Thread{ protected Socket sc; PrintWriter valja; String kasutajanimi=""; String IP; public Loim(Socket uus_sc){ try{ sc=uus_sc; valja=new PrintWriter(sc.getOutputStream(), true); IP=sc.getRemoteSocketAddress().toString(); start(); }catch(Exception e){e.printStackTrace();} } public void run(){ try{ BufferedReader sisse=new BufferedReader( new InputStreamReader(sc.getInputStream()) ); valja.println("Tere tulemast RandServ juhuarvude serverisse!"); /*valja.println("Sisesta kasutajanimi:"); //kasutajanimi=sisse.readLine(); String uusnimi=sisse.readLine(); boolean olemas=false; for(int i=0;i