SuperVCD管理系统 完整代码,带各种注释,可以拿这个项目入门。
import java.io.*;
import .*;
import java.util.*;
/**
* 这个类是socket连接的处理器
* 例如:
* <pre>
* Handler aHandler = new Handler(clientSocket, myMusicDataAccessor);
* aHandler.start();
* </pre>
*
*
*/
public class Handler extends Thread implements StoneForestProtocol {
protected Socket clientSocket;
protected ObjectOutputStream outputToClient;
protected ObjectInputStream inputFromClient;
protected MusicDataAccessor myMusicDataAccessor;
protected boolean done;
public Handler(Socket theClientSocket, MusicDataAccessor theMusicDataAccessor) throws IOException {
clientSocket = theClientSocket;
outputToClient = new ObjectOutputStream(clientSocket.getOutputStream()); inputFromClient = new ObjectInputStream(clientSocket.getInputStream());
myMusicDataAccessor = theMusicDataAccessor;
done = false;
}
public void run() {
try {
while (!done) {
log("等待命令...");
int opCode = inputFromClient.readInt();
log("opCode = " + opCode);