/Users/mw17785/Projects/gamefinder/gamefinder/trunk/src/example/Server.java |
package example;
import cs101.comm.Announcer;
import cs101.comm.GameInfo;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
public class Server {
public Server() {
Clip clip = null;
try {
AudioInputStream sound =
AudioSystem.getAudioInputStream(getClass().getResource("CLANG.AU"));
clip = AudioSystem.getClip();
clip.open(sound);
} catch (Exception e) {
e.printStackTrace();
}
try {
ServerSocket ss = new ServerSocket(0);
GameInfo gi = new GameInfo("SocketTest", "demo for class", null,
ss.getLocalPort());
Announcer announcer = new Announcer(gi);
System.out.println("Using port "+ss.getLocalPort());
while(true) {
Socket sock = ss.accept();
if (clip != null) {
clip.setFramePosition(0);
clip.loop(0);
}
new Handler(sock);
}
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
public static void main(String[] args) {
new Server();
}
}