clientsocket.java
来自「这是一个java c/s模式的通信模型源码」· Java 代码 · 共 30 行
JAVA
30 行
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 + =
减小字号Ctrl + -
显示快捷键?