package socketservertest;
import java.net.*;

/**
 * <p>Title: MIDI-server</p>
 * <p>Description: Gets commands through port 3332 and plays MIDI-files with Timidity.</p>
 */

public class StartServerThread extends Thread {
  public StartServerThread() {
  }

  /**
   * When an object implementing interface <code>Runnable</code> is used to
   * create a thread, starting the thread causes the object's <code>run</code>
   * method to be called in that separately executing thread.
   *
   * @todo Implement this java.lang.Runnable method
   */

  public void run () {
    try {
      String host = "127.0.0.1";
      InetSocketAddress socketAddress = new InetSocketAddress(host, 3332);

      java.net.ServerSocket server = new java.net.ServerSocket();
      server.bind(socketAddress);
      while (this.isAlive()) {
        java.net.Socket socket = server.accept();
        ServerThread st = new ServerThread(socket);
        st.start();

        // When client connects...
        System.out.println("Starting playback...");
      }
      } catch (java.io.IOException E) {
        E.printStackTrace();
      }
  }



}
