用于接收浏览器http 完整请求,学习用

public void test6() throws Exception{

ServerSocket server = new ServerSocket(1111);

Socket socket = null;

while((socket = server.accept())!=null){

new Processor(socket){

}.start();;

}

server.close();

}

class Processor extends Thread{

private Socket socket;

public Processor(Socket socket) {

this.socket = socket;

}

public void run() {

try{

socket.setSoTimeout(3000);

InputStream in = socket.getInputStream();

int i;

while( (i = in.read())!=-1){

System.out.print((char)i);

}

}catch(Exception e){

}finally {

try {

socket.close();

} catch (IOException e) {

}

}

}

}

猜你喜欢

转载自ktlb.iteye.com/blog/2286326