模拟B/S服务器(扩展)
模拟B/S服务器(扩展)
案例:
public class Server {
public static void main(String[] args) throws IOException {
ServerSocket socket = new ServerSocket(8888);
Socket accept = socket.accept();
InputStream is = accept.getInputStream();
int len =0;
byte[] bytes = new byte[1024];
while ((len=is.read(bytes))!=-1){
System.out.println(new String(bytes,0,len));
}
}
}
图解: