-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServer.java
More file actions
32 lines (25 loc) · 961 Bytes
/
Copy pathServer.java
File metadata and controls
32 lines (25 loc) · 961 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
package proxy;
import java.io.Closeable;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
public class Server implements Multiplier {
public Server(int port) throws IOException {
ServerSocket echoSocket = new ServerSocket(port);
Socket clientSocket = echoSocket.accept();
DataInputStream dataInputStream = new DataInputStream(clientSocket.getInputStream());
DataOutputStream dataOutputStream = new DataOutputStream(clientSocket.getOutputStream());
while (clientSocket.isConnected()) {
double left = dataInputStream.readDouble();
double right = dataInputStream.readDouble();
double result = mul(left, right);
dataOutputStream.writeDouble(result);
}
}
@Override
public Double mul(double left, double right) {
return left * right;
}
}