当前位置:网站首页>Wechat applet websocket use case
Wechat applet websocket use case
2022-06-27 05:17:00 【Tianma 3798】
One 、Asp.Net Core 6 Server-side code
Server side WebScoket The code is the same as the previous blog post :
Asp.Net Core6 WebSocket A simple case _ Tianma 3798 The blog of -CSDN Blog
Two 、 Wechat applet WebSocket Use finishing
1.wx.connectSocet() establish socket Connect tasks
Detailed address :
SocketTask | Wechat open documents
2.SocketTask Monitor processing socket Mission
SocketTask | Wechat open documents
3. Applet WebScoket Concurrent number
- 1.7.0 And above , Can exist at most at the same time 5 individual WebSocket Connect .
- 1.7.0 The following versions , A small program can only have one WebSocket Connect , If there is already a WebSocket Connect , Will automatically close the connection , And recreate a WebSocket Connect .
3、 ... and 、 Wechat applet websocket Code use cases
1.wxml
<text>pages/wx/test1/test1.wxml</text>
<input type="text" />
<button bindtap="sendClick"> send content </button>
<view wx:for="{
{result}}">
{
{item}}
</view>2.js
var socket = null; // Global definition socket object
Page({
/**
* Initial data of the page
*/
data: {
result: []
},
/**
* Life cycle function -- Monitor page loading
*/
onLoad(options) {
var _this = this;
// establish websocket
// Use of official address wss
socket = wx.connectSocket({
url: 'ws://localhost:5032/wstest/one',
success: res => {
console.info(' Connection created successfully ');
//socketTaskId: 22
// console.info(res);
}
});
// console.info(socket);
// Event monitoring
socket.onOpen(function () {
console.info(' Connection opened successfully ');
});
socket.onClose(function () {
console.info(' Connection closed successfully ');
});
socket.onError(function () {
console.info(' Connection error ');
});
// The server sends listening
socket.onMessage(function (e) {
console.info(e);
var data = e.data;
var list = _this.data.result;
list = list.concat([data]);
_this.setData({
result: list
});
});
},
// Send events
sendClick() {
socket.send({
data: ' Client test content ',
success: res => {
console.info(' The client sent successfully ');
}
});
}
})3. Running effect

more :
Asp.Net Core6 WebSocket A simple case
ASP.NET Core5.0 SignalR CORS Cross domain processing
Asp.Net Core6 WebSocket binding
边栏推荐
- [station B up dr_can learning notes] Kalman filter 3
- How JQ gets the ID name of an element
- Common programming abbreviations for orbit attitude
- 竣达技术丨多品牌精密空调集中监控方案
- 微服务系统设计——服务熔断和降级设计
- pycharm 如何安装 package
- 022 basics of C language: C memory management and C command line parameters
- 洛谷P2939 [USACO09FEB]Revamping Trails G 题解
- Opencv实现对象跟踪
- Microservice system design -- distributed lock service design
猜你喜欢

Niuke practice 101-c reasoning clown - bit operation + thinking

Web3还没实现,Web5乍然惊现!

Cognition - how to fill in 2022 college entrance examination volunteers

双位置继电器JDP-1440/DC110V

leetcode298周赛记录

Experience oceanbase database under win10

EasyExcel合并相同内容单元格及动态标题功能的实现

双位置继电器HJWS-9440

How JQ gets the reciprocal elements

什么是BFC?有什么用?
随机推荐
快速排序(非递归)和归并排序
Remapping (STM32)
Opencv实现对象跟踪
ES6 0622 III
微服务系统设计——微服务监控与系统资源监控设计
差点因为 JSON.stringify 丢了奖金...
Qt使用Valgrind分析内存泄漏
017 basics of C language: bit field and typedef
007 C语言基础:C运算符
Penetration test - file upload / download / include
Codeforces Round #802 (Div. 2)
008 C language foundation: C judgment
neo4j community与neo4j desktop冲突
【B站UP DR_CAN学习笔记】Kalman滤波3
Microservice system design -- distributed transaction service design
双位置继电器JDP-1440/DC110V
【FPGA】基于bt1120时序设计实现棋盘格横纵向灰阶图数据输出
EasyExcel合并相同内容单元格及动态标题功能的实现
Tsinghua University open source software mirror website
pycharm 如何安装 package