如何判断浏览器的请求头是不是结束
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                如何判断浏览器的请求头是不是结束
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.                        
                                
                            
                            
                            \r\n\r\n好像是結束符package?com.maple.detail3;
?
?import?java.io.FileInputStream;
?import?java.io.FileNotFoundException;
?import?java.io.IOException;
?import?java.io.InputStream;
?import?java.io.OutputStream;
?import?java.io.PrintWriter;
?import?java.net.ServerSocket;
?import?java.net.Socket;
?
?public?class?TcpServer3?{
?????public?static?void?main(String[]?args)?throws?Exception?{
?
?????????ServerSocket?serverSocket=new?ServerSocket(10000);
?????????Thread?t=null;
?????????while(true)
?????????{
?????????????Socket?socket=serverSocket.accept();
??????????????t=new?Thread(new?ReadPic(socket));
??????????????t.start();
?????????}
?????}
?
?}
?
?class?ReadPic?implements?Runnable
?{
?????Socket?socket=null;
?????
?????public?ReadPic(Socket?socket)?{
?????????this.socket=socket;
?????}
?
?????@Override
?????public?void?run()?{
?????????try?{
?????????????OutputStream?outputStream=socket.getOutputStream();
?????????????InputStream?inputStream=new?FileInputStream("c:/2.png");
?????????????
?????????????InputStream?socketInputStream=socket.getInputStream();
?????????????
?????????????
?????????????byte[]?buf=new?byte[1024];
?????????????int?len=0;
?????????????
?????????????while((len=socketInputStream.read(buf))!=-1)
?????????????{
?????????????????String?line=new?String(buf,0,len);
?????????????????System.out.println(line.length()+"??"+line);
?????????????????if(line.endsWith("\r\n\r\n"))
?????????????????{
?????????????????????System.out.println("game?is?over");
?????????????????????break;
?????????????????}
?????????????}????????????
?????????????System.out.println("kkkkkkkkkkkkkkkk");
?????????????while((len=inputStream.read(buf))!=-1)
?????????????{
?????????????????outputStream.write(buf,0,len);
?????????????????outputStream.flush();
?????????????}
?????????????socket.close();
?????????}?catch?(Exception?e)?{
?????????????e.printStackTrace();
?????????}
?????}
?}
                        
                        
                        ?
?import?java.io.FileInputStream;
?import?java.io.FileNotFoundException;
?import?java.io.IOException;
?import?java.io.InputStream;
?import?java.io.OutputStream;
?import?java.io.PrintWriter;
?import?java.net.ServerSocket;
?import?java.net.Socket;
?
?public?class?TcpServer3?{
?????public?static?void?main(String[]?args)?throws?Exception?{
?
?????????ServerSocket?serverSocket=new?ServerSocket(10000);
?????????Thread?t=null;
?????????while(true)
?????????{
?????????????Socket?socket=serverSocket.accept();
??????????????t=new?Thread(new?ReadPic(socket));
??????????????t.start();
?????????}
?????}
?
?}
?
?class?ReadPic?implements?Runnable
?{
?????Socket?socket=null;
?????
?????public?ReadPic(Socket?socket)?{
?????????this.socket=socket;
?????}
?
?????@Override
?????public?void?run()?{
?????????try?{
?????????????OutputStream?outputStream=socket.getOutputStream();
?????????????InputStream?inputStream=new?FileInputStream("c:/2.png");
?????????????
?????????????InputStream?socketInputStream=socket.getInputStream();
?????????????
?????????????
?????????????byte[]?buf=new?byte[1024];
?????????????int?len=0;
?????????????
?????????????while((len=socketInputStream.read(buf))!=-1)
?????????????{
?????????????????String?line=new?String(buf,0,len);
?????????????????System.out.println(line.length()+"??"+line);
?????????????????if(line.endsWith("\r\n\r\n"))
?????????????????{
?????????????????????System.out.println("game?is?over");
?????????????????????break;
?????????????????}
?????????????}????????????
?????????????System.out.println("kkkkkkkkkkkkkkkk");
?????????????while((len=inputStream.read(buf))!=-1)
?????????????{
?????????????????outputStream.write(buf,0,len);
?????????????????outputStream.flush();
?????????????}
?????????????socket.close();
?????????}?catch?(Exception?e)?{
?????????????e.printStackTrace();
?????????}
?????}
?}
??
轉載于:https://www.cnblogs.com/passer1991/archive/2012/11/01/2749005.html
總結
以上是生活随笔為你收集整理的如何判断浏览器的请求头是不是结束的全部內容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: 级联下拉框效果,动态加载图片
- 下一篇: 使用VS2012进行性能测试和负载测试
