Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package server;
- import java.io.*;
- import java.net.*;
- import client.NoConsistentEpsException;
- import client.NoConsistentMinSupException;
- import client.ServerException;
- import server.keyboardinput.Keyboard;
- public class Server {
- public static final int PORT = 8080;
- public static void main(String[] args)throws IOException, ServerException{
- ServerSocket ss = new ServerSocket(PORT); // Il Server si mette in ascolto sulla porta 8080
- System.out.println("Server Avviato: " + ss);
- String choice = ""; // Operazione scelta sul client
- String table_name = "";
- float minSup = 0F;
- float eps = 0F;
- String path = "";
- try{
- // Il server accetta la connessione
- Socket socket = ss.accept();
- // La connessione è avvenuta
- BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
- PrintWriter out = new PrintWriter( new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())),true);
- try{
- System.out.println("Connessione accettata: " + socket);
- //Ricevo la scelta effettuata sul menu
- choice = in.readLine();
- System.out.println("Ricevuto da Client: " + choice);
- //Se si richiede la scoperta di pattern chiusi allora si richiedono gli altri valori
- if(choice.equals("1")){
- //Invio la stringa e ricevo il nome della tabella
- out.println("Inserire nome tabella");
- table_name = in.readLine();
- System.out.println("Tabel_name: " + table_name);
- //Il Server richiede il valore di minSup e lo riceve dal client
- do{
- try{
- //Il server richiede il valore di minSup
- out.println("Inserire il valore di minSup");
- minSup = Float.parseFloat(in.readLine()); //La stringa ricevuta viene convertita in Floate assegnata a minSup
- if (minSup < 0 || minSup > 1)
- throw new NoConsistentMinSupException(); // Sollevamento
- // esplicito
- // dell'eccezione
- }catch (NoConsistentMinSupException exc) {
- System.err.println("Valore di minSup inserito non corretto");
- }
- }while (minSup < 0 || minSup > 1);
- System.out.println("minSup: " + minSup);
- //Il Server richiede il valore di eps e lo riceve dal client
- do {
- try{
- out.println("Inserire il valore di eps in ( (0,1] )");
- eps = Float.parseFloat(in.readLine());
- if (eps <= 0 || eps > 1)
- throw new NoConsistentEpsException();
- }catch (NoConsistentEpsException e) {
- System.err.println("valore di epsilon inserito non corretto");
- }
- } while (eps <= 0 || eps > 1);
- System.out.println("eps: " + eps);
- //Il Server richiede il nome del file più estensione su cui salvare (Si assume di salvare sul workspace)
- out.println("Inserire il nome del file su cui salvare");
- path = in.readLine();
- System.out.println("path: " + path);
- }
- else if(choice.equals("2")){
- System.out.println("Carico archivio");
- }
- out.println("END"); //Chiudo il ciclo su client
- }finally{
- socket.close();
- }
- }
- finally {
- System.out.println("closing...");
- ss.close();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement