?? nwserver.java
字號:
package trader.nw;
import java.io.*;
import java.net.*;
import trader.*;
import trader.db.*;
class NwServer {
int port;
private ServerSocket serverSocket;
private IoStrategy ioServer;
private Socket skt;
public NwServer(int port, IoStrategy ioServer) {
//** 1 Code in this constructor is similar (but not
//** identical) to the constructor of CommandServer
this.port = port;
this.ioServer = ioServer;
try {
serverSocket = new ServerSocket(port);
System.out.println
("NwServer created ServerSocket on port " + port);
this.acceptConnection();
} catch(Exception e) {
System.out.println("NwServer.constructor: " + e);
}
}
public void acceptConnection() {
System.out.println("NwServer.acceptConnection ");
//** 1 Code in this method is similar (but not
//** identical) to the corresponding method of CommandServer
//** Hint the skt from the acceptConnection method
// of serverSocket must be passed to the ioService
// method of the ioServer object
while(true) {
try {
skt = serverSocket.accept(); // listening;
System.out.println("NwServer.acceptConnection + accepted");
ioServer.ioService(skt);
} catch(Exception e) {
System.out.println("NwServer.acceptConnection: " + e);
}
}
}
public static void main(String args[]) {
try {
BrokerModel bd = new BrokerModelDbImpl("localhost");
BrokerServer bs = new BrokerServer(bd);
NwServer server = new NwServer(6001, bs);
} catch(Exception e) {
e.printStackTrace();
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -