You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 rivejä
1.2 KiB

  1. package xyz.nextn;
  2. import java.io.DataInputStream;
  3. import java.io.DataOutputStream;
  4. import java.io.IOException;
  5. import java.net.Socket;
  6. import java.net.UnknownHostException;
  7. public class Client {
  8. private Socket socket = null;
  9. private DataInputStream input = null;
  10. private DataOutputStream out = null;
  11. public Client(String address, int port) {
  12. try {
  13. socket = new Socket(address, port);
  14. System.out.println("Connected");
  15. input = new DataInputStream(System.in);
  16. out = new DataOutputStream(socket.getOutputStream());
  17. } catch (UnknownHostException u) {
  18. System.out.println(u);
  19. } catch (IOException i) {
  20. System.out.println(i);
  21. }
  22. String line = "";
  23. while (!line.equals("Over")) {
  24. try {
  25. line = input.readLine();
  26. out.writeUTF(line);
  27. } catch (IOException i) {
  28. System.out.println(i);
  29. }
  30. }
  31. try {
  32. input.close();
  33. out.close();
  34. socket.close();
  35. } catch (IOException i) {
  36. System.out.println(i);
  37. }
  38. }
  39. }