Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.21 KB | None | 0 0
  1. package server;
  2.  
  3. import java.io.*;
  4. import java.net.*;
  5.  
  6. import client.NoConsistentEpsException;
  7. import client.NoConsistentMinSupException;
  8. import client.ServerException;
  9. import server.keyboardinput.Keyboard;
  10.  
  11. public class Server {
  12. public static final int PORT = 8080;
  13. public static void main(String[] args)throws IOException, ServerException{
  14. ServerSocket ss = new ServerSocket(PORT); // Il Server si mette in ascolto sulla porta 8080
  15. System.out.println("Server Avviato: " + ss);
  16.  
  17. String choice = ""; // Operazione scelta sul client
  18. String table_name = "";
  19. float minSup = 0F;
  20. float eps = 0F;
  21. String path = "";
  22.  
  23. try{
  24. // Il server accetta la connessione
  25. Socket socket = ss.accept();
  26. // La connessione è avvenuta
  27.  
  28. BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
  29. PrintWriter out = new PrintWriter( new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())),true);
  30.  
  31. try{
  32. System.out.println("Connessione accettata: " + socket);
  33.  
  34. //Ricevo la scelta effettuata sul menu
  35. choice = in.readLine();
  36. System.out.println("Ricevuto da Client: " + choice);
  37.  
  38. //Se si richiede la scoperta di pattern chiusi allora si richiedono gli altri valori
  39. if(choice.equals("1")){
  40. //Invio la stringa e ricevo il nome della tabella
  41. out.println("Inserire nome tabella");
  42. table_name = in.readLine();
  43. System.out.println("Tabel_name: " + table_name);
  44.  
  45. //Il Server richiede il valore di minSup e lo riceve dal client
  46. do{
  47. try{
  48. //Il server richiede il valore di minSup
  49. out.println("Inserire il valore di minSup");
  50. minSup = Float.parseFloat(in.readLine()); //La stringa ricevuta viene convertita in Floate assegnata a minSup
  51.  
  52. if (minSup < 0 || minSup > 1)
  53. throw new NoConsistentMinSupException(); // Sollevamento
  54. // esplicito
  55. // dell'eccezione
  56. }catch (NoConsistentMinSupException exc) {
  57. System.err.println("Valore di minSup inserito non corretto");
  58. }
  59.  
  60. }while (minSup < 0 || minSup > 1);
  61. System.out.println("minSup: " + minSup);
  62.  
  63. //Il Server richiede il valore di eps e lo riceve dal client
  64. do {
  65. try{
  66. out.println("Inserire il valore di eps in ( (0,1] )");
  67. eps = Float.parseFloat(in.readLine());
  68.  
  69. if (eps <= 0 || eps > 1)
  70. throw new NoConsistentEpsException();
  71. }catch (NoConsistentEpsException e) {
  72. System.err.println("valore di epsilon inserito non corretto");
  73. }
  74.  
  75. } while (eps <= 0 || eps > 1);
  76. System.out.println("eps: " + eps);
  77.  
  78. //Il Server richiede il nome del file più estensione su cui salvare (Si assume di salvare sul workspace)
  79. out.println("Inserire il nome del file su cui salvare");
  80. path = in.readLine();
  81. System.out.println("path: " + path);
  82. }
  83.  
  84. else if(choice.equals("2")){
  85. System.out.println("Carico archivio");
  86. }
  87.  
  88. out.println("END"); //Chiudo il ciclo su client
  89.  
  90.  
  91.  
  92. }finally{
  93. socket.close();
  94. }
  95.  
  96.  
  97.  
  98. }
  99. finally {
  100. System.out.println("closing...");
  101. ss.close();
  102. }
  103. }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement