typeserver.java

来自「java threads 3th源码,包括各个章节的源代码」· Java 代码 · 共 37 行

JAVA
37
字号
package javathreads.examples.ch12.example1;import java.io.*;import java.net.*;import javathreads.examples.ch12.*;public class TypeServer extends TCPServer {    public void run(Socket data) {        try {            DataOutputStream dos =                   new DataOutputStream(data.getOutputStream());            dos.writeByte(TypeServerConstants.WELCOME);            DataInputStream dis =                  new DataInputStream(data.getInputStream());            while (true) {                byte b = dis.readByte();                if (b != TypeServerConstants.GET_STRING_REQUEST) {                    System.out.println("Client sent unknown request " + b);                    continue;                }                dos.writeByte(TypeServerConstants.GET_STRING_RESPONSE);                dos.writeUTF("Thisisateststring");                dos.flush();            }        } catch (Exception e) {            System.out.println("Client terminating: " + e);            return;        }    }    public static void main(String[] args) throws IOException {        TypeServer ts = new TypeServer();        ts.startServer(Integer.parseInt(args[0]));        System.out.println("Server ready and waiting...");    }}

⌨️ 快捷键说明

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