Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 29a3f064

Přidáno uživatelem Roman Kalivoda před téměř 4 roky(ů)

Re #9009 fix https listener issue

Zobrazit rozdíly:

Server/ServerApp/Connection/ConnectionListener.cs
10 10
using System.Diagnostics;
11 11
using System.IO;
12 12
using System.Net;
13
using System.Reflection;
13 14
using System.Net.Sockets;
14 15
using System.Text;
15 16
using System.Threading;
16 17
using System.Web;
18
using System.Security.Cryptography.X509Certificates;
17 19

  
18 20
namespace ServerApp.Connection
19 21
{
......
36 38
			string ip = GetLocalIPAddress();
37 39
			Console.WriteLine("ip : " + ip);
38 40
			HttpListener listener = new HttpListener();
39
			//HttpListener server = new HttpListener();
40
			listener.Prefixes.Add($"https://{ip}:{PORT}/");
41
			//listener.Prefixes.Add($"http://localhost:{PORT}/");
42

  
43
			listener.Start();
41
            //HttpListener server = new HttpListener();
42
            listener.Prefixes.Add($"https://*:{PORT}/");
43
            //listener.Prefixes.Add($"http://*:{PORT}/");
44

  
45
            // Set certificate via reflection ´, taken from https://github.com/dotnet/runtime/issues/27391
46
            Type hepmType = Type.GetType("System.Net.HttpEndPointManager, System.Net.HttpListener");
47
            Type heplType = Type.GetType("System.Net.HttpEndPointListener, System.Net.HttpListener");
48
            MethodInfo getEPListener = hepmType.GetMethod("GetEPListener", BindingFlags.Static | BindingFlags.NonPublic);
49
            FieldInfo heplCert = heplType.GetField("_cert", BindingFlags.NonPublic | BindingFlags.Instance);
50
            object epl = getEPListener.Invoke(null, new object[] { "*", PORT, listener, true });
51
            X509Certificate cert = new X509Certificate2("cert.p12", "changeit");
52
            heplCert.SetValue(epl, cert);
53

  
54
            listener.Start();
44 55

  
45 56
			Console.WriteLine("Listening...");
46 57

  
Server/ServerApp/Predictor/PredictionController.cs
57 57
                this.Configuration = JsonConvert.DeserializeObject<PredictorConfiguration>(json);
58 58
            } catch (System.IO.IOException e)
59 59
            {
60
                Console.WriteLine(e.ToString());
60
                Console.WriteLine("Warning: could not find a configuration file, creating a new one:");
61
                Console.WriteLine(e.Message.PadLeft(4));
61 62
                this.Configuration = PredictorConfiguration.GetDefaultConfig();
62 63
            }
63 64

  

Také k dispozici: Unified diff