FileDocCategorySizeDatePackage
MusicServer.javaAPI DocExample2191Mon Jan 24 12:49:58 GMT 2005None

MusicServer

public class MusicServer extends Object

Fields Summary
ArrayList
clientOutputStreams
Constructors Summary
Methods Summary
public voidgo()

      clientOutputStreams = new ArrayList<ObjectOutputStream>();

       try {
       ServerSocket serverSock = new ServerSocket(4242);

       while(true) {
          Socket clientSocket = serverSock.accept();
          ObjectOutputStream out = new ObjectOutputStream(clientSocket.getOutputStream());
          clientOutputStreams.add(out);


       Thread t = new Thread(new ClientHandler(clientSocket));
       t.start();


       System.out.println("got a connection");
     }
       // now if I get here I have a connection
               
      }catch(Exception ex) {
         ex.printStackTrace();
      }
   
public static voidmain(java.lang.String[] args)

         new MusicServer().go();
    
public voidtellEveryone(java.lang.Object one, java.lang.Object two)

      Iterator it = clientOutputStreams.iterator();
      while(it.hasNext()) {
        try {
           ObjectOutputStream out = (ObjectOutputStream) it.next();
           out.writeObject(one);
           out.writeObject(two);
         }catch(Exception ex) {ex.printStackTrace();}
       }