package com.day1;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.ServerSocket;
import java.net.Socket;
public class Server {
/**刘诗华
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
//创建服务器 ServerSocket对象 向系统内核申请注册一个套接字
ServerSocket serverSocket=new ServerSocket(8080);
System.out.println("等待中...");
//接受客户端请求,处理阻塞状态
Socket socket = serverSocket.accept();
//获取客户端的输入流,站的角度是服务器
InputStream in = socket.getInputStream();
//设置缓冲区
byte[] buffer=new byte[1024];
int len=-1;
StringBuilder sb=new StringBuilder();
while((len=in.read(buffer))!=-1)
{
sb.append(new String(buffer,0,len));
}
//关闭套接字对象
socket.close();
serverSocket.close();
System.out.println(sb.toString());
}
}