scoket1.java
来自「java网络编程」· Java 代码 · 共 42 行
JAVA
42 行
package scoket;
/*第1题*/
import java.net.*;
import java.io.*;
public class Scoket1 {
public Scoket1() {
}
static int SERVER_PORT=4024;
public static void main(String[] args) {
try {
Socket s = new Socket(InetAddress.getLocalHost(), SERVER_PORT);
InputStream in=s.getInputStream();
BufferedReader stdin =new BufferedReader(new InputStreamReader(in));
String s1, s2 = new String();
while((s1 = stdin.readLine())!= null)
s2 += s1 + "\n";
System.out.print("现在的时间是:"+s2);
stdin.close();
s.close();
}
catch (IOException e) {
System.out.println("Can't connect to server.");
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?