From db7bc646525ccb7fa05d63d34d4220d39f6ff04f Mon Sep 17 00:00:00 2001 From: MrTob Date: Mon, 23 Sep 2019 20:50:53 +0200 Subject: [PATCH] =?UTF-8?q?=E2=80=9Esrc/xyz/nextn/Client.java=E2=80=9C=20?= =?UTF-8?q?=C3=A4ndern?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/xyz/nextn/Client.java | 58 +++++++++++++++++++++++++++++---------- 1 file changed, 44 insertions(+), 14 deletions(-) diff --git a/src/xyz/nextn/Client.java b/src/xyz/nextn/Client.java index 11ef072..b8ccf35 100644 --- a/src/xyz/nextn/Client.java +++ b/src/xyz/nextn/Client.java @@ -1,23 +1,53 @@ package xyz.nextn; - +import java.io.DataInputStream; +import java.io.DataOutputStream; import java.io.IOException; -import java.net.InetAddress; import java.net.Socket; -import java.util.Scanner; +import java.net.UnknownHostException; -public class Client{ - private int port; - private InetAddress ip; +public class Client { + private Socket socket = null; + private DataInputStream input = null; + private DataOutputStream out = null; - public Client(int port, InetAddress ip) { - this.port = port; - this.ip = ip; - } + public Client(String address, int port) { + try { + socket = new Socket(address, port); + System.out.println("Connected"); + + + input = new DataInputStream(System.in); + + + out = new DataOutputStream(socket.getOutputStream()); + } catch (UnknownHostException u) { + System.out.println(u); + } catch (IOException i) { + System.out.println(i); + } - public void getData() throws IOException { - Scanner scn = new Scanner(System.in); - InetAddress ip = InetAddress.getByName("localhost"); - Socket s = new Socket(ip, port); + + String line = ""; + + + while (!line.equals("Over")) { + try { + line = input.readLine(); + out.writeUTF(line); + } catch (IOException i) { + System.out.println(i); + } + } + + + try { + input.close(); + out.close(); + socket.close(); + } catch (IOException i) { + System.out.println(i); + } } + }