How To Separate Header from File in Socket Connection
Hi, I'm writing a P2P program using Gnutella API, and thisi uses a socket that connects to a Gnutella server, and attempts to download a file from it. The problem is, I can't separate the header from the file itself, and use the information from the header to guide the file i/o. Here's the code:
Socket s = new Socket(IP, PORT);
InputStream is = s.getInputStream();
OutputStream os = s.getOutputStream();
os.write((
"GET /get/"+FILE_ID+"/"+FILE_NAME+" HTTP/1.0\r\n"
+ "Connection: Keep-Alive\r\n" // not necessary
+ "Range: bytes=0-\r\n" // not necessary
+ "\r\n" // not necessary
).getBytes());
When I tried to read/write into a file, the file gets corrupted/truncated since the header was stuck into the file (meaning the header of the response, like "HTTP 200 OK" or something.
I'm on a deadline. Please help!

