Javascript代码为此工作:
function testSocket()
{
var socket = io("http://localhost:3001/",{
query:{Token:"YWRtaW5Ac3RsdGVjaC5pbjpzdGxAMTIzOjE2MTEzNDE3OTk1OTY="},
});
socket.on('message-processed',(event,callback)=>{
writeToScreen(event);
});
}
但我需要在 C# 中实现它。我尝试了下面显示的代码,但它不起作用:
var ws = new WebSocket("ws://localhost:3001/socket.io/Token=YWRtaW5Ac3RsdGVjaC5pbjpz=");
ws.Connect();
ws.OnMessage += (sender, e) =>
Console.WriteLine("Laputa says: " + e.Data);
ws.Send("message-processed");
Console.ReadKey(true);