📄 clientsocket.java
字号:
import java.net.*;
import java.io.*;
public class ClientSocket {
public static void main(String[] args) {
InputStream in = null;
OutputStream out = null;
try {
Socket s = new Socket("localhost",6666);
in = s.getInputStream();
out = s.getOutputStream();
DataInputStream din = new DataInputStream(in);
String s1 = null;
if((s1=din.readUTF()) != null) {
System.out.println(s1);
}
DataOutputStream dout = new DataOutputStream(out);
dout.writeUTF("Hello Server!!!");
din.close();
dout.close();
s.close();
}catch(ConnectException e) {
System.out.println("the socket is connect exception !!");
}catch(IOException e) {
System.out.println("the io Exception is in the Socket!!");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -