astolfo96

Client

Sep 9th, 2017
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. package clientelisa;
  2.  
  3. import java.io.DataInputStream;
  4. import java.io.DataOutputStream;
  5. import java.io.IOException;
  6. import java.net.ServerSocket;
  7. import java.net.Socket;
  8. import java.util.logging.Level;
  9. import java.util.logging.Logger;
  10.  
  11. public class ClientElisa {
  12.  
  13. Socket socket;
  14. boolean stop = true;
  15.  
  16. ClientElisa() {
  17. try {
  18. socket = new Socket("127.0.0.1", 33061);
  19. DataOutputStream tmpOut = new DataOutputStream(socket.getOutputStream());
  20. tmpOut.writeUTF("10 + 10");
  21. tmpOut.flush();
  22. } catch (IOException ex) {
  23. Logger.getLogger(ClientElisa.class.getName()).log(Level.SEVERE, null, ex);
  24. }
  25.  
  26. try {
  27. ServerSocket ss = new ServerSocket(1000);
  28. while (stop) {
  29. try {
  30. socket = ss.accept();
  31. // PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
  32. // out.println("ciao");
  33. DataInputStream in = new DataInputStream(socket.getInputStream());
  34.  
  35. String str = in.readUTF().toString();
  36.  
  37. if (!str.equals("")) {
  38. System.out.println(str);
  39.  
  40.  
  41. stop = false;
  42. }
  43.  
  44. socket.close();
  45.  
  46. } catch (IOException ex) {
  47. Logger.getLogger(ClientElisa.class.getName()).log(Level.SEVERE, null, ex);
  48. }
  49. }
  50.  
  51.  
  52. } catch (IOException ex) {
  53. Logger.getLogger(ClientElisa.class.getName()).log(Level.SEVERE, null, ex);
  54. }
  55.  
  56. }
  57.  
  58. public static void main(String[] args) {
  59. ClientElisa ce = new ClientElisa();
  60. }
  61.  
  62. }
Advertisement
Add Comment
Please, Sign In to add comment