Änderungen 05.12.2023 um 14:44

This commit is contained in:
leonmcfly 2023-12-19 14:23:07 +01:00
parent f6668dfce7
commit 0729be4457
2 changed files with 26 additions and 10 deletions

View File

@ -1,7 +0,0 @@
package Prog3.src.DiningPhilosophers;
import static org.junit.jupiter.api.Assertions.*;
class ForkTest {
}

View File

@ -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()) {
@ -20,7 +36,14 @@ public class SorterClient {
scanner.close();
}
private String sort(String line){
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.";
}
}
}