|
|
@@ -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."; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |