问题标签 [websocket-sharp]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
0 回答
1566 浏览

unity3d - 主线程上的WebSocketSharp .onMessage?/ 在 Unity 中处理?

我发现很难在 Unity 中为简单的 websocket 客户端找到一个简单可靠的库。WebSocketSharp(即https://github.com/sta/websocket-sharp)看起来不错,但许多项目无法解释。

当收到的消息到达时,

测试表明它似乎到达(总是?有时?)不是主要的 Unity 线程。

有人知道吗

  1. 事实上它总是不是主线程,还是可以变化?

  2. 如果总是另一个线程,实际上它总是同一个线程,还是变化/很多?

由于每个使用 websocket 客户端的 Unity 应用程序都必须这样做,我很惊讶没有 100 多个关于如何处理传入消息的讨论,包括在 WebSocketSharp 页面上,

但这就是我要做的,就像在 Unity 这样的基于帧的引擎中处理“线程”的通常方式:

那么那么

  1. 在 Unity 内部使用时,这确实是处理 WebSocketSharp 中的线程问题的常用方法吗?

鉴于有数十亿个带有 websockets 客户端的 Unity 应用程序,这一定是一条非常成熟的道路。

0 投票
0 回答
100 浏览

c# - Websocket 尖锐,从 onmessage 读取服务器变量

您好,我是网络套接字的新手,所以想知道我在这里做错了什么,我有一个服务器和客户端

代码看起来像这样

问题是当我向客户端发送 globalvar 时它总是 = 1

有任何想法吗?

0 投票
1 回答
1548 浏览

c# - C# WebSocketSharp.WebSocketException:不是 WebSocket 握手响应

我想从网站上抓取实时数据,我决定使用 webSocket - 锋利的库。我的问题是,使用相同的代码,我可以解析来自特定网站的数据,而不能从另一个网站解析数据。

程序抛出此异常:WebSocket.connect:0|WebSocketSharp.WebSocketException: Not a WebSocket 握手响应。

我尝试使用或不使用自定义标题。

我该怎么做才能进行有效的握手?

(PS:我可以解析没有来自第一个网站的自定义标题的数据)

更新

在 URL 中有一个 uid 参数 wss://blabla.com/zap/? uid=5829062969032768

每次刷新网页时,此 uid 都会发生变化。我认为握手是必要的。有没有办法重现它?

0 投票
2 回答
221 浏览

http - WebSocket-Sharp 不响应公共 IP 地址

我在公共互联网 IP 上托管 WebSocket-Sharp 时遇到问题。在本地它工作正常。此问题发生在 Windows 和 Linux 上。我没有收到超时或 HTTP 状态代码,页面立即阻塞。我 99% 确定我正确设置了端口转发;我尝试过使用 Android 调制解调器、VPN 和常规 NAT 路由器设置。

我尝试了以下组合:

192.168.1.2:80 8080 5000 39393

0.0.0.0:....

公网IP:……

0 投票
0 回答
451 浏览

c# - c# websocket-sharp 无法连接套接字。错误“不包括没有 Sec-WebSocket-Protocol 标头,或者它的值无效”

我正在尝试(使用 Windows 窗体应用程序)连接到sec-websocket-protocol用于身份验证的套接字。在浏览器中一切正常,但是当我尝试使用 c# 模拟该连接时,它失败并出现错误Includes no Sec-WebSocket-Protocol header, or it has an invalid value.。日志文件:

Sec-WebSocket-Protocolvalue 是我从另一个获得的代码。API我认为我从 api 正确获取了值。我多次检查过。

这是我的 C# 代码:

设置错误是否可能Sec-WebSocket-Protocol改变值SslConfiguration。(我不确定我应该使用System.Security.Authentication.SslProtocols.Tls12)?

我试过:
1-Sec-WebSocket-Protocol从标题中删除-->响应错误:HEADER_AUTH_WS or HEADER_WEB_SOCKET_SUB_PROTOCOL is empty
2-删除设置的行SslConfiguration.EnabledSslProtocols-->没有任何改变。

0 投票
1 回答
672 浏览

c# - 我想在 C# 中实现客户端 Web 套接字连接

Javascript代码为此工作:

但我需要在 C# 中实现它。我尝试了下面显示的代码,但它不起作用:

0 投票
1 回答
389 浏览

c# - Unity - My script stops working on Editor but works on my builds(android, ios)

Installed Unity Version is 2020.2.1f1

I'm developing an online multiplayer game using Unity. I have 2 different connection types; Http and Websocket(using Websocketsharp: https://github.com/sta/websocket-sharp, I've installed it using Nuget). Http get/post, Websocket connect/send/close works totally fine but when I call function (directly or by sending events) after response, most of the time my code inside that called function is not completed on editor(works fine on builds-android,ios). I'm not sure if this problem is related to http/websocket but it's related to online connection because I've experienced the same issue when I was developing a real-time multiplayer game using Unity & Gamesparks.

I can do basic functions like print etc. until I call one of the following functions loadscene, update UI, or call another function in same/different script(only first one of these works, everything after that won't run). Console doesn't show any error and game doesn't pause or crash. It runs on same fps but that part of the code won't continue. Other scripts/updates works fine. I've searched a lot but couldn't even find a related topic.

WebSocket Client:

Connection Manager:

Game Manager

I've found a trick to handle this situation but I didn't like it as a proper solution and don't wanna spend resources for Update calls. When I call function (directly or by sending events) after response, inside the called function I set bool to true and in Update call I call the necessary function when the bool is true and the code works totally fine.

---The Trick---

Game Manager

What can be the reason of my script working on builds but not on unity editor?

Thank you!

0 投票
0 回答
285 浏览

c# - Azure Web App Service Websockets 使用 Websocket Sharp

我正在使用 WebsocketSharp 网络标准库来创建一个 websocket 服务器。在我的 Web 应用服务中,Websocket 已启用。始终开启已启用。当我在本地运行此服务器时,我可以零问题地使用它。一旦我部署到 Azure Web App Service,我最终会收到一条错误消息,指出我正在访问一个禁止的端口:

到目前为止,我的代码是:

当我发布时,构建和发布成功,但由于上述错误,应用程序无法启动。

0 投票
0 回答
323 浏览

c# - 握手服务器 websocketsharp 库出错

这是我的例外轨道。如果我尝试向 websocket handhskake 发送 http 请求,一切正常 101 但是如果我尝试连接到 wsSharp,我会得到 Exeptions MY CODE:

0 投票
2 回答
732 浏览

c# - WebSocket 异步发送和接收数据(使用 NuGet websocket-client)

我正在努力使用 NuGet 包 websocket-client ( https://github.com/Marfusios/websocket-client )的观察者模式

与 WebSocket 服务器的连接稳定且正在运行。

每个请求在负载中都有一个请求 ID。客户端将其发送到服务器,服务器以 ID 和真实数据进行响应。

在客户端,我需要将每个响应分配给相应的请求。

我以为我可以这样做:

但它实际上从不跳转到 subscribe 方法。我用错了吗?