📄 sclient.java
字号:
import java.io.*;
import java.net.*;
public class SClient
{
public static void main(String[] args)
{
String s=null;
Socket mysocket;
DataInputStream in=null;
DataOutputStream out=null;
try
{
mysocket = new Socket("localhost",4321);
in = new DataInputStream(mysocket.getInputStream());
out = new DataOutputStream(mysocket.getOutputStream());
out.writeUTF("我是客户机,向你请求连接。");
while (true)
{
s=in.readUTF();
if(s!=null) break;
}
mysocket.close();
}
catch(IOException e){System.out.println("无法连接");}
System.out.println(s);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -