Browse Source

Änderungen 05.12.2023 um 14:44

master
leonmcfly 10 months ago
parent
commit
0729be4457
2 changed files with 26 additions and 10 deletions
  1. 0
    7
      src/DiningPhilosophers/ForkTest.java
  2. 26
    3
      src/DistributedSorter/SorterClient.java

+ 0
- 7
src/DiningPhilosophers/ForkTest.java View File

@@ -1,7 +0,0 @@
package Prog3.src.DiningPhilosophers;

import static org.junit.jupiter.api.Assertions.*;

class ForkTest {

}

+ 26
- 3
src/DistributedSorter/SorterClient.java 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.";
}

}
}

Loading…
Cancel
Save