import java.net.*; import java.io.*; public class Client extends Thread { private Socket s = null; private ObjectInputStream in = null; private ObjectOutputStream out = null; private static String host = "atlas.dsv.su.se"; private static int port = 4949; private static String encoding = "gsm"; private SoundRecorder soundRecorder; private SoundPlayer soundPlayer; public static void main(String[] args) { if(args.length != 0) { host = args[0]; if(args.length != 1) { port = Integer.parseInt(args[1]); } } new Client(); } public Client() { try { s = new Socket(host, port); System.out.println("CONNECTED TO: " + host + " - ON PORT: " + port); out = new ObjectOutputStream(s.getOutputStream()); } catch (IOException ioe) { System.out.println("COULD NOT CONNECT: "+ ioe); System.exit(1); } soundRecorder = new SoundRecorder(this); soundPlayer = new SoundPlayer(); soundRecorder.record(); start(); } public void run() { while(true) { try { // Obs! Detta måste vara här!!! in = new ObjectInputStream(s.getInputStream()); Storage storage = (Storage)in.readObject(); soundPlayer.play(storage); } catch(Exception e) { } } } public void send(Storage storage) { try { out.writeObject(storage); } catch(IOException ioe) { System.err.println("I/O problems: " + ioe); } } }