微信公开课
微信公开课小程序热门讨论关于「小程序链接内网电脑」的小程序开发问题
补充:电脑端开TCP端口号为60000的端口,server端口小程序可以连接端口,但不能发数据请问问什么varapp=getApp();varSocketTask=false;varsocketOpen=false;varsocketMsgQueue=Page({data:{inputVa
展开:电脑端开TCP端口号为60000的端口,server端口小程序可以连接端口,但不能发数据请问问什么varapp=getApp();varSocketTask=false;varsocketOpen=false;varsocketMsgQueue=[]Page({data:{inputValue:123,returnValue:1,},onLoad:function(options){},onReady:function(){wxconnectSocket({url=ws:172202021:60000})wxonSocketOpen(function(res){socketOpen=true;for(vari=0;i<socketMsgQueuelength;i++){sendSocketMessage(socketMsgQueue[i])}socketMsgQueue=[];})functionsendSocketMessage(msg){if(socketOpen){wxsendSocketMessage({data:msg});}else{socketMsgQueuepush(msg)}}}})通过WebSocket连接发送数据,需要先wxconnectSocket,并在wxonSocketOpen回调之后才能发送functionsendSocketMessage(data){consolelog(通过WebSocket连接发送数据)if(socketOpen){SocketTasksend({data:JSONstringify(data)data:data},function(res){consolelog(已发送,res)})}else{socketMsgQueuepush(msg)}}
更多有关「小程序链接内网电脑」的讨论可以前往微信公开课小程序参与互动哦!了解更多