📄 client.java
字号:
import java.net.*;
import java.io.*;
public class client
{ public static void main(String[] args) throws Exception
{
InetAddress addr = InetAddress.getByName(null);
System.out.println("this computer is IP is:" + addr);
Socket socket = new Socket(addr,4000);
System.out.println("Socket = "+socket);
try {
PrintWriter out = new PrintWriter(new BufferedWriter(
new OutputStreamWriter(socket.getOutputStream())),true);
out.println("Data from client: How are you?");
BufferedReader in = new BufferedReader(
new InputStreamReader(socket.getInputStream()));
System.out.println(in.readLine());
}
finally
{ System.out.println("Closing socket...");
socket.close();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -