将Websocket与Poco库连接 [英] Connect Websocket with Poco libraries
问题描述
我想使用 Echo Test Websocket ://www.appinf.com/docs/poco/Poco.Net.WebSocket.htmlrel =nofollow> Poco C ++库。
为了这样做,我的代码应该设置Websocket:
HTTPClientSession cs websocket.org);
HTTPRequest请求(HTTPRequest :: HTTP_GET,/ ws);
HTTPResponse响应;
WebSocket * m_psock = new WebSocket(cs,request,response);
m_psock-> close(); // close immidiately
但它不工作:
我收到一条错误消息这:
Poco :: Exception:WebSocket异常:无法升级到WebSocket连接:找不到
有人可以帮忙吗?
亲切问候
解决方案未找到错误是HTTP服务器返回的标准HTTP 404未找到。
通过从
更改资源,我的代码可以正常工作。 code>到/ ws
/
:HTTPRequest请求HTTPRequest :: HTTP_GET,/);
并添加以下行
request.set(origin,http://www.websocket.org);在创建新的
WebSocket
之前,
<我认为这是一个头对,许多(或所有?)WebSocket服务器期望。I am trying to connect to the Echo Test Websocket using the Poco C++ libraries. In order to do so here is my code which should set up the Websocket:
HTTPClientSession cs("echo.websocket.org"); HTTPRequest request(HTTPRequest::HTTP_GET, "/ws"); HTTPResponse response; WebSocket* m_psock = new WebSocket(cs, request, response); m_psock->close(); //close immidiately
However it does not work: I am getting an error message like this:
Poco::Exception: WebSocket Exception: Cannot upgrade to WebSocket connection: Not Found
Can anybody help?
kind regards
解决方案The 'Not Found' error is the standard HTTP 404 Not Found returned by the HTTP server. It generally means the resource you are requesting does not exist.
I got your code to work by changing the resource from
"/ws"
to"/"
:HTTPRequest request(HTTPRequest::HTTP_GET, "/");
and adding the following line
request.set("origin", "http://www.websocket.org");
before creating the new
WebSocket
. I think it's a header pair that many (or all?) WebSocket servers expect.这篇关于将Websocket与Poco库连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!