]> matita.cs.unibo.it Git - logicplayer.git/blob - Server/server/tesi/src/com/company/superServer.java
d755d9c77129707af1a4af55258cbdc145dfa4fe
[logicplayer.git] / Server / server / tesi / src / com / company / superServer.java
1 package com.company;
2
3 import java.io.*;
4 import java.lang.Thread;
5 import java.security.*;
6 import javax.net.ssl.*;
7
8 import java.nio.file.FileSystems;
9 import java.nio.file.Path;
10
11
12 class superServer
13 {
14         public static void main(String[] args)
15         {
16                 String ksName = global.home+global.keyStoreName;
17                 char ksPass[] = global.keyStorePass.toCharArray();
18                 char ctPass[] = global.keyStorePass.toCharArray();
19
20                 //thread di controllo directory esercizi
21                 Path pathToWatch = FileSystems.getDefault().getPath(global.locationEsercizi);
22                 DirectoryWatcher dirWatcher = new DirectoryWatcher(pathToWatch);
23                 Thread dirWatcherThread = new Thread(dirWatcher);
24                 dirWatcherThread.start();
25
26                 //thread che si occupa del lato http
27                 httpget regServer=new httpget();
28                 Thread httpServer=new Thread(regServer);
29                 httpServer.start();
30
31                 while(true)
32                 {
33                         try
34                         {
35                                 KeyStore ks = KeyStore.getInstance("JKS");
36                                 ks.load(new FileInputStream(ksName), ksPass);
37                                 KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
38                                 kmf.init(ks, ctPass);
39                                 SSLContext sc = SSLContext.getInstance("TLS");
40                                 sc.init(kmf.getKeyManagers(), null, null);
41                                 SSLServerSocketFactory ssf = sc.getServerSocketFactory();
42                                 SSLServerSocket s= (SSLServerSocket) ssf.createServerSocket(global.portaServer);
43                                 System.out.println("Server started:");
44                                 while(true)
45                                 {
46                                         SSLSocket c = (SSLSocket) s.accept();
47                                         System.out.println("CSC: debug 1");
48                                         guestServer guest=new guestServer(c);
49                                         Thread t=new Thread(guest);
50                                         t.start();
51                                 }
52                         }
53                         catch (Exception e)
54                         {
55                                 e.printStackTrace();
56                         }
57                 }
58         }
59 }