Guest User

Untitled

a guest
Aug 4th, 2017
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. public final class PingServer {
  2. private Socket socket = new Socket();
  3. private String host = null;
  4. private int port = 0;
  5. private String[] data = new String[999];
  6.  
  7. public PingServer(String host, int port) {
  8. this.port = port;
  9. this.host = host;
  10. try{
  11. socket.connect(new InetSocketAddress(host,port));
  12. OutputStream out = socket.getOutputStream();
  13. InputStream in = socket.getInputStream();
  14. out.write(0xFE);
  15.  
  16. int b;
  17. StringBuffer str = new StringBuffer();
  18. while((b = in.read()) != -1){
  19. if(b != 0 && b > 16 && b != 255 && b != 23 && b != 24){
  20. str.append((char)b);
  21. }
  22. }
  23.  
  24. data = str.toString().split("§");
  25. data[0] = data[0].substring(1,data[0].length());
  26. }catch(IOException e){
  27. e.printStackTrace();
  28. }
  29. }
  30. public String getMotd(){
  31. return data[0];
  32. }
  33.  
  34. public int getOnline(){
  35. return Integer.parseInt(data[1]);
  36. }
  37.  
  38. public int getMax(){
  39. return Integer.parseInt(data[2]);
  40. }
  41. public void update() {
  42. try{
  43. socket.close();
  44. socket = new Socket();
  45. socket.connect(new InetSocketAddress(host,port));
  46. OutputStream out = socket.getOutputStream();
  47. InputStream in = socket.getInputStream();
  48. out.write(0xFE);
  49.  
  50. int b;
  51. StringBuffer str = new StringBuffer();
  52. while((b = in.read()) != -1){
  53. if(b != 0 && b > 16 && b != 255 && b != 23 && b != 24){
  54. str.append((char)b);
  55. }
  56. }
  57.  
  58. data = str.toString().split("§");
  59. data[0] = data[0].substring(1,data[0].length());
  60.  
  61. }catch(IOException e){
  62. e.printStackTrace();
  63. }
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment