Socket有两种类型:1、TCP套接字 2、UDP套接字
服务端socket
ServerSocket sever = new ServerSocket(port);
Socket socket = sever.accept();
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(socket.getOutPutStream()));
out.write();
out.flush();
socket.close();
客户端socket
Socket socket = new Socket("localhost","8080");
socket.getInputStream();
socekt.getOutPutStream();
out.write();
out.flush();
socket.close();
时间: 2024-11-05 13:43:11