clean up fhs
This commit is contained in:
38
praktikum-5/aufgabe-3/Client.java
Normal file
38
praktikum-5/aufgabe-3/Client.java
Normal file
@@ -0,0 +1,38 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user