Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
1ee59b6417 | |||
a4a80afe73 | |||
aa3482f033 | |||
c611622a63 | |||
640b568e28 | |||
87815d5bf6 | |||
fdfd1872f4 | |||
f07832d5f2 |
@@ -2,4 +2,9 @@
|
|||||||
|
|
||||||
#### 介绍
|
#### 介绍
|
||||||
|
|
||||||
WebSocket测试工具
|
WebSocket测试工具, 后续逐步增加功能。
|
||||||
|
|
||||||
|
功能列表:
|
||||||
|
|
||||||
|
- [x] ws/wss链接发送消息
|
||||||
|
- [x] 定时 ping
|
@@ -1,10 +1,12 @@
|
|||||||
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;
|
||||||
using WebSocketTool.Base;
|
using WebSocketTool.Base;
|
||||||
using WebSocketTool.Util;
|
using WebSocketTool.Util;
|
||||||
|
using WebSocketTool.View.Dialog;
|
||||||
using LogManager = log4net.LogManager;
|
using LogManager = log4net.LogManager;
|
||||||
|
|
||||||
namespace WebSocketTool.Client
|
namespace WebSocketTool.Client
|
||||||
@@ -105,7 +107,7 @@ namespace WebSocketTool.Client
|
|||||||
|
|
||||||
public void Connect()
|
public void Connect()
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(WsUrl))
|
if (string.IsNullOrEmpty(WsUrl) || (!WsUrl.StartsWith("wss://") && !WsUrl.StartsWith("ws://")))
|
||||||
{
|
{
|
||||||
view.AppendInfo($"Hint {TimeUtil.GetCurrentDateTime()} \n 请输入正确的WebSocket地址");
|
view.AppendInfo($"Hint {TimeUtil.GetCurrentDateTime()} \n 请输入正确的WebSocket地址");
|
||||||
return;
|
return;
|
||||||
@@ -125,9 +127,17 @@ namespace WebSocketTool.Client
|
|||||||
view.AppendInfo($"Hint {TimeUtil.GetCurrentDateTime()} \n Start Connect Socket");
|
view.AppendInfo($"Hint {TimeUtil.GetCurrentDateTime()} \n Start Connect Socket");
|
||||||
if (IsProxyChecked)
|
if (IsProxyChecked)
|
||||||
{
|
{
|
||||||
view.AppendInfo($"use proxy: {ProxyAddress}");
|
if (!string.IsNullOrEmpty(ProxyAddress))
|
||||||
|
{
|
||||||
|
view.AppendInfo($"Hint use proxy: {ProxyAddress}");
|
||||||
mClient.SetHttpProxy(ProxyAddress, ProxyUserName, ProxyPassword);
|
mClient.SetHttpProxy(ProxyAddress, ProxyUserName, ProxyPassword);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
view.ShowToast("请输入代理地址!");
|
||||||
|
view.AppendInfo($"use proxy address is empty!");
|
||||||
|
}
|
||||||
|
}
|
||||||
mClient.ConnectAsync();
|
mClient.ConnectAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -222,7 +232,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 +244,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 +259,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(() =>
|
||||||
|
@@ -75,11 +75,18 @@ namespace WebSocketTool.Client
|
|||||||
{
|
{
|
||||||
viewModel.Close();
|
viewModel.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Window GetWindow()
|
||||||
|
{
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface IClientView
|
public interface IClientView
|
||||||
{
|
{
|
||||||
void ShowToast(string msg);
|
void ShowToast(string msg);
|
||||||
void AppendInfo(string info);
|
void AppendInfo(string info);
|
||||||
|
|
||||||
|
Window GetWindow();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -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"))
|
||||||
{
|
{
|
||||||
|
@@ -12,7 +12,7 @@ using System.Windows;
|
|||||||
[assembly: AssemblyConfiguration("")]
|
[assembly: AssemblyConfiguration("")]
|
||||||
[assembly: AssemblyCompany("DevWiki")]
|
[assembly: AssemblyCompany("DevWiki")]
|
||||||
[assembly: AssemblyProduct("WebSocketTool")]
|
[assembly: AssemblyProduct("WebSocketTool")]
|
||||||
[assembly: AssemblyCopyright("Copyright DevWiki © 2022")]
|
[assembly: AssemblyCopyright("Copyright DevWiki © 2023")]
|
||||||
[assembly: AssemblyTrademark("")]
|
[assembly: AssemblyTrademark("")]
|
||||||
[assembly: AssemblyCulture("")]
|
[assembly: AssemblyCulture("")]
|
||||||
|
|
||||||
@@ -51,5 +51,5 @@ using System.Windows;
|
|||||||
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
|
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
|
||||||
//通过使用 "*",如下所示:
|
//通过使用 "*",如下所示:
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
[assembly: AssemblyVersion("1.0.1")]
|
[assembly: AssemblyVersion("1.0.3")]
|
||||||
[assembly: AssemblyFileVersion("1.0.1")]
|
[assembly: AssemblyFileVersion("1.0.3")]
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
set version=1.0.0
|
set version=1.0.3
|
||||||
|
|
||||||
if not "%~1"=="" (
|
if not "%~1"=="" (
|
||||||
set version=%1
|
set version=%1
|
||||||
|
@@ -9,7 +9,7 @@
|
|||||||
<OutputType>Library</OutputType>
|
<OutputType>Library</OutputType>
|
||||||
<RootNamespace>WebSocketSharp</RootNamespace>
|
<RootNamespace>WebSocketSharp</RootNamespace>
|
||||||
<AssemblyName>websocket-sharp</AssemblyName>
|
<AssemblyName>websocket-sharp</AssemblyName>
|
||||||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
|
||||||
<SignAssembly>true</SignAssembly>
|
<SignAssembly>true</SignAssembly>
|
||||||
<AssemblyOriginatorKeyFile>websocket-sharp.snk</AssemblyOriginatorKeyFile>
|
<AssemblyOriginatorKeyFile>websocket-sharp.snk</AssemblyOriginatorKeyFile>
|
||||||
<FileUpgradeFlags>
|
<FileUpgradeFlags>
|
||||||
|
Reference in New Issue
Block a user