zoukankan      html  css  js  c++  java
  • 如何判断浏览器的请求头是不是结束

    \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();
             }
         }
     }

      

  • 相关阅读:
    python ratelimit使用
    团队怎样去做技术规划
    分词语义提取工具
    今日头条推荐系统
    要选择做有价值的事情
    总结与规划
    性能使用到极限
    流量运营
    Stanford CoreNLP使用需要注意的一点
    七年总结
  • 原文地址:https://www.cnblogs.com/passer1991/p/2749005.html
Copyright © 2011-2022 走看看