Änderungen 05.12.2023 um 14:44
This commit is contained in:
parent
f6668dfce7
commit
0729be4457
@ -1,7 +0,0 @@
|
||||
package Prog3.src.DiningPhilosophers;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class ForkTest {
|
||||
|
||||
}
|
@ -1,13 +1,29 @@
|
||||
package Prog3.src.DistributedSorter;
|
||||
package DistributedSorter;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.Socket;
|
||||
import java.util.Arrays;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class SorterClient {
|
||||
public class SorterClient implements Runnable{
|
||||
public static void main(String[] args) {
|
||||
SorterClient client = new SorterClient();
|
||||
client.run();
|
||||
}
|
||||
|
||||
public static void sendLine(Socket socket, String line) throws IOException {
|
||||
OutputStream out = socket.getOutputStream();
|
||||
PrintWriter writer = new PrintWriter(out);
|
||||
writer.println(line);
|
||||
writer.flush();
|
||||
}
|
||||
|
||||
public static String receiveLine(Socket socket) throws IOException {
|
||||
InputStream in = socket.getInputStream();
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
|
||||
return reader.readLine();
|
||||
}
|
||||
|
||||
public void run(){
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
while (scanner.hasNextLine()) {
|
||||
@ -21,6 +37,13 @@ public class SorterClient {
|
||||
}
|
||||
|
||||
private String sort(String line) {
|
||||
try (Socket socket = new Socket("localhost", 12345)) {
|
||||
|
||||
sendLine(socket, line);
|
||||
return receiveLine(socket);
|
||||
} catch (Exception e) {
|
||||
return "Error connecting to the server.";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user