Advertisement
TrodelHD

Untitled

May 7th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. package Connection;
  2.  
  3. import java.io.IOException;
  4. import java.io.ObjectInputStream;
  5. import java.io.ObjectOutputStream;
  6. import java.net.InetAddress;
  7. import java.net.Socket;
  8. import java.net.UnknownHostException;
  9.  
  10. public class BuildConnection {
  11.  
  12. private int port;
  13. private String ip;
  14. private Socket skt;
  15. private ObjectOutputStream output;
  16. private ObjectInputStream input;
  17.  
  18.  
  19.  
  20.  
  21. public BuildConnection(String i, int p) {
  22.  
  23. this.ip = i;
  24. this.port = p;
  25. trytoconnect();
  26.  
  27. }
  28.  
  29.  
  30.  
  31. public void trytoconnect() {
  32.  
  33. System.out.println("trying to connect");
  34. try {
  35. this.skt = new Socket(InetAddress.getByName(this.ip), this.port);
  36. System.out.println("verbunden");
  37. setupStreams();
  38.  
  39. } catch (UnknownHostException e) {
  40. System.out.println("fehler verbinden");
  41. e.printStackTrace();
  42. } catch (IOException e) {
  43. System.out.println("fehler verbinden");
  44. e.printStackTrace();
  45. }
  46.  
  47.  
  48. }
  49.  
  50. public ObjectOutputStream getOutput() {
  51. return output;
  52. }
  53.  
  54.  
  55.  
  56. public void setOutput(ObjectOutputStream output) {
  57. this.output = output;
  58. }
  59.  
  60.  
  61.  
  62. public ObjectInputStream getInput() {
  63. return input;
  64. }
  65.  
  66.  
  67.  
  68. public void setInput(ObjectInputStream input) {
  69. this.input = input;
  70. }
  71.  
  72.  
  73.  
  74. private void setupStreams() throws IOException{
  75.  
  76. this.output = new ObjectOutputStream(this.skt.getOutputStream());
  77. this.output.flush();
  78. this.input = new ObjectInputStream(this.skt.getInputStream());
  79. }
  80.  
  81.  
  82.  
  83.  
  84. public int getPort() {
  85. return port;
  86. }
  87.  
  88. public void setPort(int port) {
  89. this.port = port;
  90. }
  91.  
  92. public String getIp() {
  93. return ip;
  94. }
  95.  
  96. public void setIp(String ip) {
  97. this.ip = ip;
  98. }
  99.  
  100. public Socket getSkt() {
  101. return skt;
  102. }
  103.  
  104. public void setSkt(Socket skt) {
  105. this.skt = skt;
  106. }
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement