Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. public static boolean connect = false;
  2. public static boolean click = false;
  3. public static boolean serverisworking = false;
  4.  
  5. if(connect) {
  6. ip = ((TextField) scene.lookup("#iptextfield")).getText();
  7. System.out.println("Server connected to this"+ip+"IP");
  8. connect = false;
  9. }
  10. if(click) {
  11. client client = new client();
  12. try {
  13. client.run(((TextArea) scene.lookup("#messagetextarea")).getText());
  14. ((TextArea) scene.lookup("#outputtextarea")).setText("#messagetextarea");
  15. } catch(IOException ex) {
  16. Logger.getLogger(Lighproject.class.getName()).log(Level.SEVERE, null, ex);
  17. }
  18. click = false;
  19. }
  20. if (serverisworking && !Constants.text.equals("")){
  21. System.out.println("server is working");
  22. System.out.println(server.txt+"Catch error here ");
  23. ((TextArea) scene.lookup("#outputtextarea")).appendText(Constants.text);
  24. serverisworking = false;
  25. }
  26. }
  27. }, 0, 3000);
  28. }
  29.  
  30. public void click() {
  31. click = true;
  32. }
  33.  
  34. public void connect() {
  35. connect = true;
  36. serverisworking = true;
  37. }
  38.  
  39. public static String txt="";
  40.  
  41. public static void main(String[] args) throws IOException {
  42. ServerSocket ss = new ServerSocket(8000);
  43. while(true){
  44. Socket s =ss.accept();
  45. System.out.println("Client is connected");
  46. Lighproject.serverisworking=true;
  47.  
  48. InputStreamReader in = new InputStreamReader (s.getInputStream());
  49. BufferedReader bf = new BufferedReader(in);
  50. String str = bf.readLine();
  51. System.out.println("Client"+str);
  52. Constants.text = str;
  53.  
  54. PrintWriter pr = new PrintWriter(s.getOutputStream());
  55. pr.println("Hey there");
  56. pr.flush();
  57. }
  58. }
  59.  
  60. public static String updateAndReturn(){
  61. return txt;
  62. }
  63.  
  64. public static void run(String txt) throws IOException {
  65. Socket s = new Socket(Lighproject.ip,8000);
  66. PrintWriter pr = new PrintWriter (s.getOutputStream());
  67. pr.println(txt);
  68. pr.flush();
  69. InputStreamReader in = new InputStreamReader (s.getInputStream());
  70. BufferedReader bf = new BufferedReader (in);
  71.  
  72. String str = bf.readLine();
  73. System.out.println("Server"+str);
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement