import java.io.*; import java.net.*; class TaxServer { public static void main(String[] args) throws IOException { Server server = new Server(); server.start(); Client client = new Client("127.0.0.1"); client = new Client("127.0.0.1"); client = new Client("127.0.0.1"); } } class Server extends Thread { public static final int PORT = 2357; ServerSocket serversock; Server() throws IOException { serversock = new ServerSocket(PORT); } public void run() { int services = 0; while(services++ < 3) { try { Socket sock = serversock.accept(); DataInputStream dis = new DataInputStream(sock.getInputStream()); DataOutputStream dos = new DataOutputStream(sock.getOutputStream()); int salery = dis.readInt(); dos.writeInt( (int) (salery * Math.random())); // always return 0% tax.. yes that's my dream! dis.close(); dos.close(); } catch(IOException e) {System.err.println(e); } } } } class Client { Client(String url) throws IOException { Socket sock = new Socket(url, Server.PORT); DataOutputStream dos = new DataOutputStream(sock.getOutputStream()); DataInputStream dis = new DataInputStream(sock.getInputStream()); int salery = (int) (Math.random()*100000); dos.writeInt(salery); System.out.println("with a salery of " + salery + " you must pay " + dis.readInt() + " tax"); dos.close(); dis.close(); } }