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

📄 ports.java

📁 Java经典例程 从外国一大学计算机教授出版物下载的代码 经典
💻 JAVA
字号:
import java.io.*;
import java.net.*;
import javagently.*;

class Ports {
  /* The Ports porgram            J M Bishop 1997
   * -----------------		    updated August 2000
   *
   * For checking the response from various ports
   * on a remote computer.
   * Illusrates sockets
   */

  public static void main(String[] args) {
    String computer;
    int port;

    if (args.length > 0) computer = args[0];
    else computer = "syd.cs.up.ac.za";
    if (args.length > 1) port = Integer.parseInt(args[1]);
    else port = 13; // the clock port

    new Ports (computer, port);
  }

  Ports (String computer, int port) {

    System.out.println("Accessing port "+port+" on "+ computer+"\n");
    try {

      // Create a socket to the given port.
      // Set up an input stream to read what the socket on that
      // side provides.

      Socket t = new Socket(computer, port);
      Stream in = new Stream(t.getInputStream());

      // Read from the server until readLine
      // returns no more data
      while (true) {
        String s = in.readLine();
        if (s == null) break;
        else System.out.println(s);
      }
    }
    catch(IOException e) { System.out.println("Error" + e); }
  }
}

⌨️ 快捷键说明

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