\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();
}
}
}
标签:java,请求,是不是,io,new,import,浏览器,buf,socket
From: https://blog.51cto.com/u_16066377/6185098