程序设计基础4-3-WebSocket会话API.pptxVIP

  • 0
  • 0
  • 约小于1千字
  • 约 14页
  • 2026-01-26 发布于河南
  • 举报

第4章小程序必备API;WebSocket会话API;1、wx.connectSocket参数说明;并发数;2、wx.onSocketOpen;3、wx.onSocketError;4、wx.sendSocketMessage;wx.sendSocketMessage参数说明;5、wx.onSocketMessage;6、wx.closeSocket;7、wx.onSocketClose;示例代码;--index.js--

Page({

data:{

msg:,

sendMsg:[],

socketOpen:false,

resData:[]

},

createConn:function(){

varpage=this;

wx.connectSocket({

url:wss://:8888/api/socketServer,

data:{

x:,

y:

},

header:{

content-type:Application/json

},

method:GET

});

wx.onSocketOpen(function(res){

console.log(res);

page.setData({socketOpen:true});

console.log(WebSocket连接已打开!)

});

wx.onSocketError(function(res){

console.log(WebSocket连接打开失败,请检查!)

})

},;演示效果

文档评论(0)

1亿VIP精品文档

相关文档