websocket测试修改
This commit is contained in:
parent
a70384370a
commit
a6d8193fce
|
|
@ -39,7 +39,7 @@ namespace WasteConsoleTest
|
||||||
wSocketClient.OnError += WSocketClient_OnError;
|
wSocketClient.OnError += WSocketClient_OnError;
|
||||||
wSocketClient.Open();
|
wSocketClient.Open();
|
||||||
var myService = host.Services.GetRequiredService<IMyService>();
|
var myService = host.Services.GetRequiredService<IMyService>();
|
||||||
SetTimeOut();
|
// SetTimeOut();
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
string cmd = Console.ReadLine();
|
string cmd = Console.ReadLine();
|
||||||
|
|
@ -126,6 +126,14 @@ namespace WasteConsoleTest
|
||||||
fileStream.Write(content, 0, content.Length);
|
fileStream.Write(content, 0, content.Length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//如果收到的消息为type=6心跳包,需要响应Pong
|
||||||
|
if(jsondata !=null && jsondata.type == 6)
|
||||||
|
{
|
||||||
|
var senddata = @"{
|
||||||
|
""type"": 6
|
||||||
|
}";
|
||||||
|
wSocketClient.Send(senddata);
|
||||||
|
}
|
||||||
Console.WriteLine($"{DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")},收到的消息:{data}");
|
Console.WriteLine($"{DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")},收到的消息:{data}");
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|
@ -170,7 +178,7 @@ namespace WasteConsoleTest
|
||||||
int timestamp = GetTimestamp();
|
int timestamp = GetTimestamp();
|
||||||
var garbageC2SDto = new GarbageC2SDto
|
var garbageC2SDto = new GarbageC2SDto
|
||||||
{
|
{
|
||||||
weight = 10.01,
|
weight = 50.25,
|
||||||
trash = "251658245",
|
trash = "251658245",
|
||||||
scanningTime = timestamp,
|
scanningTime = timestamp,
|
||||||
d_status = 0,
|
d_status = 0,
|
||||||
|
|
@ -372,15 +380,19 @@ namespace WasteConsoleTest
|
||||||
Task.Run(() =>
|
Task.Run(() =>
|
||||||
{
|
{
|
||||||
DateTime startime = DateTime.Now;
|
DateTime startime = DateTime.Now;
|
||||||
while (wSocketClient.State == WebSocketState.Open)
|
while (true)
|
||||||
{
|
{
|
||||||
if ((DateTime.Now - startime).TotalSeconds >= 13)
|
if(wSocketClient.State == WebSocketState.Open)
|
||||||
{
|
{
|
||||||
//发送心跳包
|
if ((DateTime.Now - startime).TotalSeconds >= 15)
|
||||||
var message = @"{
|
{
|
||||||
|
//发送心跳包
|
||||||
|
var message = @"{
|
||||||
""type"": 6
|
""type"": 6
|
||||||
}";
|
}";
|
||||||
wSocketClient.Send(message);
|
wSocketClient.Send(message);
|
||||||
|
startime = DateTime.Now;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue