c# - WebSocketSharp 异常:System.PlatformNotSupportedException:“此平台不支持操作。”
问题描述
我正在使用通过安全 websocket 与 node.js 服务器通信的 C# 应用程序。还有一个 javascript 客户端连接到节点服务器上托管的同一个 websocket。javascript 客户端连接成功连接到节点服务器。但是 c# 应用程序会抛出标题中描述的错误。
我使用了 chrome 的 SimpleWebSocketClient 扩展来连接到我的套接字。这工作正常。我还为 C# 应用程序尝试了 websocket4net。这也不起作用。我在我的 c# 应用程序中使用了 wss://echo.websocket.org websocket,它运行良好。但是我必须设置_socket.SslConfiguration.EnabledSslProtocols = System.Security.Authentication.SslProtocols.tls12;
节点服务器
const app = require('express')()
const fs = require("fs"); // file system core module
var https = require("https").createServer({
cert: fs.readFileSync(__dirname + "/certs/cert.pem"),
key: fs.readFileSync(__dirname + "/certs/key.pem")
}, app)
const express = require("express"); // web framework external module
// Setup and configure Express http server. Expect a subfolder called "static" to be the web root.
app.use(express.static(__dirname + "/static/"));
const ws = require('ws')
const wss = new ws.Server({
server: https
});
wss.on('connection', function connection(ws) {
ws.on('message', function incoming(message) {
console.log('received: %s', message);
ws.send('reply from server : ' + message)
});
ws.send('something');
});
// Listen on port 8080
https.listen(8080, () => {
console.log('listening on https://localhost:8080')
})
这是 C# 代码
_socket = new WebSocket("wss://127.0.0.1:8080");
_id = Guid.NewGuid().ToString();
_socket.OnOpen += (sender, e) =>
{
Console.WriteLine("WebSocket Connection is now Open with ID: " + _id);
};
_socket.OnMessage += (sender, e) =>
{
Console.WriteLine("On Message");
Console.WriteLine(e.Data);
};
_socket.Connect();
我很困惑为什么我的 C# 应用程序不起作用。它应该能够建立连接,就像wss://echo.websocket.org
解决方案
推荐阅读
- php - Docker alpine 图像上的 PHP HTTP 扩展
- java - java程序星球使用枚举
- r - 从 Date 类变量中删除 NA
- r - 使用 R Kernel 从 jupyter notebook 将绘图保存为 JPEG 或 PDF
- sql - 如果没有返回行,SQL 返回默认值
- python - 字节到整数的转换
- ruby-on-rails - Rails:有没有办法在 Rails 中构建基于动态角色的授权?
- python - 如何将单个键的值列表从字典列表写入 excel/csv
- asp.net - StackExchange.Redis.RedisTimeoutException:执行 EVAL 超时
- javascript - OT_TIMEOUT Session.publish :: 无法在合理的时间内发布