⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nwserver.java

📁 面向对象的设计思想
💻 JAVA
字号:
import java.io.*;
import java.net.*;
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 ");
    
    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);
      }
    }
  }

 
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -