]> matita.cs.unibo.it Git - logicplayer.git/blobdiff - server/tesi/src/com/company/superServer.java
Shuffling.
[logicplayer.git] / server / tesi / src / com / company / superServer.java
diff --git a/server/tesi/src/com/company/superServer.java b/server/tesi/src/com/company/superServer.java
new file mode 100644 (file)
index 0000000..d755d9c
--- /dev/null
@@ -0,0 +1,59 @@
+package com.company;
+
+import java.io.*;
+import java.lang.Thread;
+import java.security.*;
+import javax.net.ssl.*;
+
+import java.nio.file.FileSystems;
+import java.nio.file.Path;
+
+
+class superServer
+{
+       public static void main(String[] args)
+       {
+               String ksName = global.home+global.keyStoreName;
+               char ksPass[] = global.keyStorePass.toCharArray();
+               char ctPass[] = global.keyStorePass.toCharArray();
+
+               //thread di controllo directory esercizi
+               Path pathToWatch = FileSystems.getDefault().getPath(global.locationEsercizi);
+               DirectoryWatcher dirWatcher = new DirectoryWatcher(pathToWatch);
+               Thread dirWatcherThread = new Thread(dirWatcher);
+               dirWatcherThread.start();
+
+               //thread che si occupa del lato http
+               httpget regServer=new httpget();
+               Thread httpServer=new Thread(regServer);
+               httpServer.start();
+
+               while(true)
+               {
+                       try
+                       {
+                               KeyStore ks = KeyStore.getInstance("JKS");
+                               ks.load(new FileInputStream(ksName), ksPass);
+                               KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
+                               kmf.init(ks, ctPass);
+                               SSLContext sc = SSLContext.getInstance("TLS");
+                               sc.init(kmf.getKeyManagers(), null, null);
+                               SSLServerSocketFactory ssf = sc.getServerSocketFactory();
+                               SSLServerSocket s= (SSLServerSocket) ssf.createServerSocket(global.portaServer);
+                               System.out.println("Server started:");
+                               while(true)
+                               {
+                                       SSLSocket c = (SSLSocket) s.accept();
+                                       System.out.println("CSC: debug 1");
+                                       guestServer guest=new guestServer(c);
+                                       Thread t=new Thread(guest);
+                                       t.start();
+                               }
+                       }
+                       catch (Exception e)
+                       {
+                               e.printStackTrace();
+                       }
+               }
+       }
+}