mytimeclient.java

来自「服务器端和客户端程序」· Java 代码 · 共 31 行

JAVA
31
字号
import java.net.*;
import java.io.*;

public class MyTimeClient
{
	public static void main(String[] args)
	{
		try{
		Socket s= new Socket ("127.0.0.1",1001);
		PrintStream out = new PrintStream(s.getOutputStream());
		BufferedReader in = new BufferedReader(new InputStreamReader
		(s.getInputStream()));
		String x = in.readLine();
		if(!x.equals("PASSWORD")){
			System.out.println("Server is not time server");
			System.exit(0);
		}  else {
			out.println("chain");
		}
		x=in.readLine();
		if(x.equals("WRONG")){
			System.out.println("worong password");
		} else {
			System.out.println(x);
		}
		out.close();
		s.close();
		in.close();		
	}catch(IOException e){}
	}
}

⌨️ 快捷键说明

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