nwserver.java
来自「this is a trade sale system realized by 」· Java 代码 · 共 57 行
JAVA
57 行
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 + =
减小字号Ctrl + -
显示快捷键?