Advertisement
Guest User

Untitled

a guest
May 25th, 2015
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4. import java.io.PrintWriter;
  5. import java.net.Socket;
  6. import java.net.UnknownHostException;
  7.  
  8.  
  9. public class Bridge {
  10. static Socket s;
  11. static PrintWriter w;
  12. static String myname = null;
  13. public static void connect(String myname, String ip){
  14. Bridge.myname = myname;
  15. try {
  16. s = new Socket(ip, 9843);
  17. } catch (UnknownHostException e) {
  18. e.printStackTrace();
  19. } catch (IOException e) {
  20. e.printStackTrace();
  21. }
  22. try {
  23. w = new PrintWriter(s.getOutputStream());
  24. } catch (IOException e) {
  25. e.printStackTrace();
  26. }
  27. try {
  28. final BufferedReader read = new BufferedReader(new InputStreamReader(s.getInputStream()));
  29. new Thread(){
  30. public void run(){
  31. String raw;
  32. try {
  33. while((raw=read.readLine())!=null){
  34. //The Bungee the message is coming from
  35. String sourceBungee = raw.split("~")[0];
  36. //The command
  37. String cmd = raw.split("~")[1];
  38.  
  39. //****************************************************
  40. //Handle your stuff here
  41. //****************************************************
  42. }
  43. } catch (IOException e) {
  44. e.printStackTrace();
  45. }
  46. }
  47. }.start();
  48. } catch (IOException e) {
  49. e.printStackTrace();
  50. }
  51.  
  52. }
  53. public static void send(String cmd){
  54. w.println(myname+"~"+cmd);
  55. }
  56.  
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement