-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClient.java
More file actions
37 lines (31 loc) · 956 Bytes
/
Copy pathClient.java
File metadata and controls
37 lines (31 loc) · 956 Bytes
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
package proxy;
import java.io.Closeable;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;
public class Client implements Multiplier , Closeable{
private final Socket socket;
private final DataOutputStream output;
private final DataInputStream input;
public Client(int port) throws IOException {
socket = new Socket("localhost", port);
output = new DataOutputStream(socket.getOutputStream());
input = new DataInputStream(socket.getInputStream());
}
@Override
public Double mul(double left, double right) {
try {
output.writeDouble(left);
output.writeDouble(right);
return input.readDouble();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
@Override
public void close() throws IOException {
socket.close();
}
}