时间:2019-05-08 来源:小程序工厂
C# socket端:
namespace WebSocketTest
{
public class Program
{
public static void Main(string[] args)
{
try
{
FleckLog.Level = LogLevel.Debug;
var allSockets = new List
var server = new WebSocketServer("wss://0.0.0.0");
server.ListenerSocket.NoDelay = true;
var currPath = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
server.Certificate = new X509Certificate2(currPath + ("MyCert.pfx"), "************");
server.Start(socket =>
{
socket.OnOpen = () => Console.WriteLine("Open!"); //业务内容已隐藏
socket.OnClose = () => Console.WriteLine("Close!");//业务内容已隐藏
socket.OnMessage = message => socket.Send(message);//业务内容已隐藏
});
var input = Console.ReadLine();
while (input != "exit")
{
foreach (var socket in allSockets.ToList())
{
socket.Send(input);
}
input = Console.ReadLine();
}
}
catch(Exception e)
{
Console.WriteLine(e);
}
}
}
}
微信小程序端:
wx.connectSocket({
url: “**********”,
header: {
'content-type': 'application/json'
},
});
wx.onSocketError(function(res) {
console.log('WebSocket连接打开失败,请检查!'+res.errMsg);
//业务逻辑已隐藏
});
报错输出log为:WebSocket连接打开失败,请检查!未能完成操作。(“OSStatus”错误-9801。)
socket报错:
提供一下出现问题的机型和微信版本,以及能复现问题的简单代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)。
已发送到主贴,请问需要私信发给你吗?
按照教程提供代码片段:https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html
wechatide://minicode/XEYUClms7S35
将微信小程序端的代码片段放进去
本文网址:http://www.91bianli.com/kaifazhinan/78744.html