import java.io.*; import java.net.*; public class Tripsuserver{ static final int pordinr=3001; static final String masin="ws11.cs3.tpu.ee"; static final String lopp=".ots"; public static void main(String argumendid[]) throws Exception{ ServerSocket ss=new ServerSocket(Tripsuserver.pordinr); while(true){ Socket sc1=ss.accept(); new DataOutputStream(sc1.getOutputStream()).writeBytes(".margiksX "+ "Oota paarilist"); System.out.println("Esimene"); Socket sc2=ss.accept(); new DataOutputStream(sc2.getOutputStream()).writeBytes(".margiks0"); System.out.println("Teine"); new Tripsuloim(sc1, sc2); } } } class Tripsuloim extends Thread{ Socket[] sc=new Socket[2]; public Tripsuloim(Socket usc1, Socket usc2){ sc[0]=usc1; sc[1]=usc2; start(); } public void run(){ try{ DataInputStream sisse[]=new DataInputStream[2]; DataOutputStream valja[]=new DataOutputStream[2]; for(int i=0; i<2; i++){ sisse[i]=new DataInputStream(sc[i].getInputStream()); valja[i]=new DataOutputStream(sc[i].getOutputStream()); } valja[0].writeBytes(".kaikVaba"); boolean veel=true; while(veel){ String vastus=sisse[0].readLine(); kirjuta(valja, vastus); if(!vastus.equals(Tripsuserver.lopp)){ vastus=sisse[1].readLine(); kirjuta(valja, vastus); } if(vastus.equals(Tripsuserver.lopp))veel=false; } for(int i=0; i<2; i++){ sc[i].close(); } }catch(Exception e){ System.out.println("Probleem:"+e); } } private void kirjuta(DataOutputStream[] pw, String teade){ for(int i=0; i