-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClient.java
More file actions
39 lines (32 loc) · 1.2 KB
/
Client.java
File metadata and controls
39 lines (32 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package Proxy;
import java.io.*;
import java.net.*;
/**
* Class that manages the connection between the original client and the server
* This class also does the modifications required
*
*/
public class Client{
private Socket client;
public Client(String host, int port) throws IOException{
this.client = new Socket(host, port);
}
public InputStream getInputStream() throws IOException{
return this.client.getInputStream();
}
public OutputStream getOutputStream() throws IOException{
return this.client.getOutputStream();
}
//Method to send the GET request to the server
public BufferedWriter write(BufferedReader input, String header)throws IOException{
BufferedWriter output = new BufferedWriter(new OutputStreamWriter(this.client.getOutputStream()));
output.write(header + "\r\n");
String headerLine;
while((headerLine = input.readLine()) != null && !headerLine.isEmpty()){
System.out.println("HEADERLINE: " + headerLine);
output.write(headerLine + "\r\n");
}
output.write("\r\n");
return output;
}
}