39 lines
946 B
Java
39 lines
946 B
Java
package 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);
|
|
}
|
|
}
|
|
}
|