SHARE
TWEET

Untitled

a guest Jan 24th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ublic class Connection {
  2. Thread con;
  3. Thread send;
  4. private Socket socket = null;
  5. private String ip;
  6. private int port;
  7.  
  8.  
  9. public Connection(String ip, int port) {
  10. this.ip = ip;
  11. this.port = port;
  12.  
  13.  
  14. }
  15.  
  16. public void connect() {
  17.  
  18. if (con != null) {
  19. con.stop();
  20. }
  21.  
  22. con = new Thread(new Runnable() {
  23. @Override
  24. public void run() {
  25. try {
  26. socket = new Socket(ip, port);
  27. } catch (IOException e) {
  28. e.printStackTrace();
  29. }
  30. }
  31. });
  32.  
  33. con.start();
  34.  
  35.  
  36. }
  37.  
  38.  
  39. public void send(final String text) {
  40.  
  41. try {
  42.  
  43. PrintWriter p = new PrintWriter(socket.getOutputStream());
  44. p.write(text);
  45. p.flush();
  46. p.close();
  47.  
  48. } catch (IOException e) {
  49. e.printStackTrace();
  50. }
  51.  
  52. }
  53.  
  54.  
  55.  
  56.  
  57.  
  58. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top