优化wss链接问题
This commit is contained in:
parent
1572f31a45
commit
f07832d5f2
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Net.Security;
|
using System.Net.Security;
|
||||||
|
using System.Security.Cryptography.X509Certificates;
|
||||||
using System.Timers;
|
using System.Timers;
|
||||||
using log4net;
|
using log4net;
|
||||||
using WebSocketSharp;
|
using WebSocketSharp;
|
||||||
@ -222,7 +223,7 @@ namespace WebSocketTool.Client
|
|||||||
|
|
||||||
public void StopPing()
|
public void StopPing()
|
||||||
{
|
{
|
||||||
view.AppendInfo($"You {TimeUtil.GetCurrentDateTime()} \n StopPing");
|
App.RunOnUIThread(() => view.AppendInfo($"You {TimeUtil.GetCurrentDateTime()} \n StopPing"));
|
||||||
if (pingTimer != null)
|
if (pingTimer != null)
|
||||||
{
|
{
|
||||||
pingTimer.Stop();
|
pingTimer.Stop();
|
||||||
@ -234,23 +235,10 @@ namespace WebSocketTool.Client
|
|||||||
{
|
{
|
||||||
view.AppendInfo($"Hint {TimeUtil.GetCurrentDateTime()} \n InitSocketClient");
|
view.AppendInfo($"Hint {TimeUtil.GetCurrentDateTime()} \n InitSocketClient");
|
||||||
mClient = new SocketClient(WsUrl);
|
mClient = new SocketClient(WsUrl);
|
||||||
mClient.SetServerCertificateValidationCallback((sender, certificate, chain, errors) =>
|
if (WsUrl.StartsWith("wss:"))
|
||||||
{
|
{
|
||||||
App.RunOnUIThread(() => { view.AppendInfo($"ServerCertificateError:{errors}"); });
|
mClient.SetServerCertificateValidationCallback(CertificateValidationCallback);
|
||||||
Log.Info($"error:{errors}");
|
|
||||||
Log.Info($"Issuer: {certificate.Issuer},Subject:{certificate.Subject}");
|
|
||||||
Log.Info("ChainStatus:");
|
|
||||||
foreach (var status in chain.ChainStatus)
|
|
||||||
{
|
|
||||||
Log.Info($"{status.StatusInformation}: {status}");
|
|
||||||
}
|
}
|
||||||
Log.Info("ChainElements:");
|
|
||||||
foreach (var element in chain.ChainElements)
|
|
||||||
{
|
|
||||||
Log.Info($"element: {element.Certificate},{element.Information}");
|
|
||||||
}
|
|
||||||
return errors == SslPolicyErrors.None;
|
|
||||||
});
|
|
||||||
mClient.OpenEvent += ClientOnOpenEvent;
|
mClient.OpenEvent += ClientOnOpenEvent;
|
||||||
mClient.CloseEvent += ClientOnCloseEvent;
|
mClient.CloseEvent += ClientOnCloseEvent;
|
||||||
mClient.ErrorEvent += ClientOnErrorEvent;
|
mClient.ErrorEvent += ClientOnErrorEvent;
|
||||||
@ -262,6 +250,26 @@ namespace WebSocketTool.Client
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool CertificateValidationCallback(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
|
||||||
|
{
|
||||||
|
App.RunOnUIThread(() => { view.AppendInfo($"ServerCertificateError:{errors}"); });
|
||||||
|
Log.Info($"error:{errors}");
|
||||||
|
Log.Info($"Issuer: {certificate.Issuer},Subject:{certificate.Subject}");
|
||||||
|
Log.Info("ChainStatus:");
|
||||||
|
foreach (var status in chain.ChainStatus)
|
||||||
|
{
|
||||||
|
Log.Info($"{status.StatusInformation}: {status}");
|
||||||
|
}
|
||||||
|
|
||||||
|
Log.Info("ChainElements:");
|
||||||
|
foreach (var element in chain.ChainElements)
|
||||||
|
{
|
||||||
|
Log.Info($"element: {element.Certificate},{element.Information}");
|
||||||
|
}
|
||||||
|
|
||||||
|
return errors == SslPolicyErrors.None;
|
||||||
|
}
|
||||||
|
|
||||||
private void ClientOnMessageEvent(object sender, MessageEventArgs e)
|
private void ClientOnMessageEvent(object sender, MessageEventArgs e)
|
||||||
{
|
{
|
||||||
App.RunOnUIThread(() =>
|
App.RunOnUIThread(() =>
|
||||||
|
@ -16,10 +16,12 @@ namespace WebSocketTool.Client
|
|||||||
public event EventHandler<ErrorEventArgs> ErrorEvent;
|
public event EventHandler<ErrorEventArgs> ErrorEvent;
|
||||||
public event EventHandler<EventArgs> OpenEvent;
|
public event EventHandler<EventArgs> OpenEvent;
|
||||||
public event EventHandler<CloseEventArgs> CloseEvent;
|
public event EventHandler<CloseEventArgs> CloseEvent;
|
||||||
|
public string Url { get; private set; }
|
||||||
|
|
||||||
public SocketClient(string url)
|
public SocketClient(string url)
|
||||||
{
|
{
|
||||||
Log.Info($"create socket:{url}");
|
Log.Info($"create socket:{url}");
|
||||||
|
Url = url;
|
||||||
mSocket = new WebSocket(url);
|
mSocket = new WebSocket(url);
|
||||||
if (url.StartsWith("wss"))
|
if (url.StartsWith("wss"))
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user