Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. package server;
  2.  
  3. import java.io.*;
  4. import java.net.*;
  5.  
  6. import client.ServerException;
  7.  
  8. public class Server {
  9. public static final int PORT = 8080;
  10. public static void main(String[] args)throws IOException, ServerException{
  11. ServerSocket ss = new ServerSocket(PORT); // Il Server si mette in ascolto sulla porta 8080
  12. System.out.println("Server Avviato: " + ss);
  13.  
  14. String choice = ""; // Operazione scelta sul client
  15. String table_name = "";
  16. float minSup = 0F;
  17.  
  18. try{
  19. // Il server accetta la connessione
  20. Socket socket = ss.accept();
  21. // La connessione è avvenuta
  22.  
  23. BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
  24. PrintWriter out = new PrintWriter( new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())),true);
  25.  
  26. try{
  27. System.out.println("Connessione accettata: " + socket);
  28.  
  29. // Il Server legge ciò che il Client ha mandato
  30. while(true){
  31. choice = in.readLine();
  32. if(choice.equals("1")){
  33. out.println("Inserire il nome della tabella");
  34. table_name = choice;
  35.  
  36. out.println("Inserire un valore di minSup compreso tra [0,1]");
  37. minSup = Float.valueOf(choice).floatValue();
  38. out.println("END");
  39. }else if(choice.equals("2")){
  40. // ....
  41. }
  42. if (choice.equals("END")) break;
  43. System.out.println("Ricevuto da Client: " + choice);
  44. }
  45.  
  46. }finally{
  47. socket.close();
  48. }
  49.  
  50.  
  51.  
  52. }
  53. finally {
  54. System.out.println("closing...");
  55. ss.close();
  56. }
  57. }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement