Browse Source

„src/xyz/nextn/Client.java“ ändern

master
Tobias Link 1 year ago
parent
commit
db7bc64652
1 changed files with 44 additions and 14 deletions
  1. +44
    -14
      src/xyz/nextn/Client.java

+ 44
- 14
src/xyz/nextn/Client.java View File

@@ -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);
}
}

}

Loading…
Cancel
Save