mirror of
https://github.com/milimoe/FunGame-Testing.git
synced 2025-04-22 04:09:34 +08:00
测试 websocket
This commit is contained in:
parent
ca07c4d9ff
commit
8cea6dfa3e
@ -1,5 +1,4 @@
|
|||||||
using System.Collections;
|
using Milimoe.FunGame.Core.Api.Utility;
|
||||||
using Milimoe.FunGame.Core.Api.Utility;
|
|
||||||
using Milimoe.FunGame.Core.Library.Common.Network;
|
using Milimoe.FunGame.Core.Library.Common.Network;
|
||||||
|
|
||||||
namespace Milimoe.FunGame.Testing.Tests
|
namespace Milimoe.FunGame.Testing.Tests
|
||||||
@ -8,23 +7,36 @@ namespace Milimoe.FunGame.Testing.Tests
|
|||||||
{
|
{
|
||||||
public WebSocketTest()
|
public WebSocketTest()
|
||||||
{
|
{
|
||||||
|
bool quit = false;
|
||||||
|
HTTPClient? client = null;
|
||||||
TaskUtility.NewTask(async () =>
|
TaskUtility.NewTask(async () =>
|
||||||
{
|
{
|
||||||
HTTPClient client = await HTTPClient.Connect("localhost", 22223, false, "ws");
|
string[] strings = ["oshima.fungame.fastauto"];
|
||||||
ArrayList list = [];
|
client = await HTTPClient.Connect("localhost", 5000, false, "ws", strings, false);
|
||||||
list.Add(new string[] { "oshima.fungame.fastauto" });
|
if (client.Connected)
|
||||||
list.Add(false);
|
|
||||||
Console.WriteLine(NetworkUtility.JsonSerialize(new SocketObject(Core.Library.Constant.SocketMessageType.Connect, Guid.NewGuid(), list)));
|
|
||||||
await client.Send(Core.Library.Constant.SocketMessageType.Connect, list);
|
|
||||||
while (true)
|
|
||||||
{
|
{
|
||||||
await Task.Delay(1000);
|
client.AddSocketObjectHandler(obj =>
|
||||||
await client.Send(Core.Library.Constant.SocketMessageType.HeartBeat);
|
{
|
||||||
|
Console.WriteLine(NetworkUtility.JsonSerialize(obj));
|
||||||
|
if (obj.SocketType == Core.Library.Constant.SocketMessageType.Connect)
|
||||||
|
{
|
||||||
|
client.Token = obj.GetParam<Guid>(2);
|
||||||
|
}
|
||||||
|
if (obj.SocketType == Core.Library.Constant.SocketMessageType.Disconnect)
|
||||||
|
{
|
||||||
|
quit = true;
|
||||||
|
client.Close();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}).OnError(Console.WriteLine);
|
}).OnError(Console.WriteLine);
|
||||||
while (true)
|
while (!quit)
|
||||||
{
|
{
|
||||||
string str = Console.ReadLine() ?? "";
|
string str = Console.ReadLine() ?? "";
|
||||||
|
if (str == "quit")
|
||||||
|
{
|
||||||
|
client?.Send(Core.Library.Constant.SocketMessageType.Disconnect);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user