0%

20230131 測試 Fork Github 上的開源專案 websocket-sharp 並引用到自己的專案

測試 Fork Github 上的開源專案 websocket-sharp 並引用到自己的專案

repo

引用來源: sta/websocket-sharp

測試結果: websocket-sharp-tester

測試步驟

  1. Fork from sta/websocket-sharp

  2. 改寫 websocket-sharp.csproj (變成 net6.0 )

1
2
3
4
5
6
7
8
9
10
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>websocket_sharp</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
  1. 刪除snk、刪除AssemblyInfo.cs

  2. 建置成功並複製 websocket-sharp.dll

  3. 建立測試主程式 websocket-sharp-tester

    1
    dotnet new console -f net6.0 -n websocket-sharp-tester
  4. 在 websocket-sharp-tester.csproj 加上引用 websocket-sharp.dll 的設定

    1
    2
    3
    4
    5
    <ItemGroup>
    <Reference Include="websocket-sharp">
    <HintPath>../dll/websocket-sharp.dll</HintPath>
    </Reference>
    </ItemGroup>
  5. 找一個可以測試 WebSocket 的網站,並加上測試的主程式
    Online WebSocket Tester

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
using WebSocketSharp;

//https://www.piesocket.com/websocket-tester
using (var ws = new WebSocketSharp.WebSocket("wss://demo.piesocket.com/v3/channel_123?api_key=VCXCEuvhGcBDP7XhiJJUDvR1e1D3eiVjgZ9VRiaV&notify_self"))
{
ws.SslConfiguration.EnabledSslProtocols = System.Security.Authentication.SslProtocols.Tls12 | System.Security.Authentication.SslProtocols.Tls11 | System.Security.Authentication.SslProtocols.Tls;

ws.OnMessage += (sender, e) =>
{
WS_OnMessage(sender, e);
Console.WriteLine("WebSocket says: " + e.Data);
};

ws.Connect();

ws.Send("Hello");

while (true)
{
ws.Ping("test");
Task.Delay(10000).Wait();
}

Console.ReadKey(true);
}

static void WS_OnMessage(object sender, MessageEventArgs e)
{
//Process Data...
Console.WriteLine(e.Data);
Console.WriteLine();
Console.WriteLine();
}
  1. 確定測試 ok 程式可正常運作
    desc