This commit is contained in:
Hinse 2021-08-07 18:33:27 +08:00
parent 0d60acf8dd
commit 967b877220
3 changed files with 47 additions and 20 deletions

View File

@ -41,6 +41,13 @@ namespace Waste.Application
_loggerService.AddLogger(msg, 1);
return "success";
}
[HttpGet]
public void ConnectServer()
{
}
[HttpGet]
public async Task TestSendAsync()
{

View File

@ -25,6 +25,8 @@
</div>
<div class="layui-inline">
<button class="btn btn-primary btn-lg js-send" type="button">发送</button>
<button class="btn btn-primary btn-lg js-connect" type="button">握手</button>
<button class="btn btn-primary btn-lg js-hello" type="button">sayHello</button>
</div>
</div>
</div>
@ -35,6 +37,7 @@
</div>
@section Scripts{
<script type="text/javascript">
//第一步调用 /
$(".js-start").on("click", function () {
initWebSocket();
});
@ -42,31 +45,47 @@
var val = $("#Content").val();
sendData("", val, "");
});
$(".js-connect").on("click", function () {
var val = {
"protocol": "messagepack",
"version":1
};
var data = JSON.stringify(val);
sendData(data);
});
$(".js-hello").on("click", function () {
var val = {
"protocol": "messagepack",
"version": 1
};
var data = JSON.stringify(val);
sendData(data);
});
var webSocket;
//d:内容
function sendData(d) {
initWebSocket();
if (webSocket.OPEN && webSocket.readyState == 1) {
let time = new Date().getTime(); //1603009495724,精确到毫秒
var s = {
"type": 1,
"headers": {
"device": "08d92497-09cb-4d1d-8c47-44443caa6896",
"secret": "oWxxKZwwHvVxQhdE",
"time": time,
"os": 12,
"script": 2,
"baseProgrameLang": 109,
"dev": true
},
"invocationId": "Nil",
"target": "sayHello",
"arguments": [
"Hello Test Message"
]
};
var aa = JSON.stringify(s);
webSocket.send(aa);
//let time = new Date().getTime(); //1603009495724,精确到毫秒
//var s = {
// "type": 1,
// "headers": {
// "device": "08d92497-09cb-4d1d-8c47-44443caa6896",
// "secret": "oWxxKZwwHvVxQhdE",
// "time": time,
// "os": 12,
// "script": 2,
// "baseProgrameLang": 109,
// "dev": true
// },
// "invocationId": "Nil",
// "target": "sayHello",
// "arguments": [
// "Hello Test Message"
// ]
//};
var s = "<";
webSocket.send(d+s);
}
if (webSocket.readyState == 2 || webSocket.readyState == 3) {
$("#div_receive").append("WebSocket closed");

View File

@ -11,6 +11,7 @@ namespace Waste.Web.Entry.Pages.Socket
{
public void OnGet()
{
}
}
}