public void startServer() {
try {
//建立server用的socket (port不能小於1024)
echoServer = new ServerSocket(port);
}
catch (IOException e) {
System.out.println(e);
}
//每當一個device連線產生時,就產生一個新的thread去處理這個連線 並且等待下一個device連進來
while ( true ) {
try {
clientSocket = echoServer.accept();
numConnections ++;
Server2Connection oneconnection = new Server2Connection(clientSocket, numConnections, this);
new Thread(oneconnection).start();
}
catch (IOException e) {
System.out.println(e);
}
}
}
}
沒有留言:
張貼留言