package praktikum5.aufgabe3; import java.net.Socket; import java.net.UnknownHostException; import java.util.Scanner; import java.io.OutputStreamWriter; import java.io.IOException; public class Client { private int port; public Client(int port) { this.port = port; } public void send(String msg) throws IOException { var socket = new Socket("localhost", port); var out = socket.getOutputStream(); var writer = new OutputStreamWriter(out); writer.write(msg); writer.flush(); writer.close(); } public static void main(String[] args) { try { int port = 4711; var client = new Client(port); var reader = new Scanner(System.in); while (true) { var msg = reader.nextLine(); client.send(msg); } } catch (Exception e) { System.out.println(e); } } }