• 如何判断浏览器的请求头是不是结束


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

      

  • 相关阅读:
    C#Ref和Out作用于引用对象时的理解
    Docker-.Net Core部署
    微服务-基于Grpc的进程通信-Protobuf-net.Grpc(4-3)
    微服务-基于Grpc的进程通信-Grpc服务注册与发现 (4-2)
    微服务-基于Grpc的进程通信-简单使用(4-1)
    ELK-Windows下系统安装(1)
    Visual Studio 2019中如何使用Git
    VS2019下载速度快完成时突然变得极慢
    Swagger 发布服务器导出Excel失败,本地导出没问题
    发布到服务器后导出Excel失败
  • 原文地址:https://www.cnblogs.com/passer1991/p/2749005.html
Copyright © 2020-2023  润新知