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); _loggerService.AddLogger(msg, 1);
return "success"; return "success";
} }
[HttpGet]
public void ConnectServer()
{
}
[HttpGet] [HttpGet]
public async Task TestSendAsync() public async Task TestSendAsync()
{ {

View File

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

View File

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