我试图通过使用C ++来连接echo.websocket.org来使用安全的websocket。 它适用于 https://www.websocket.org/echo.html
的javascript我的解决方案是使用Poco库,我的代码如下所示。
Poco::Net::initializeSSL();
Poco::Net::Context context(Poco::Net::Context::CLIENT_USE, "", "", "", Poco::Net::Context::VERIFY_RELAXED, 9, false, "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
Poco::Net::HTTPSClientSession Client("echo.websocket.org", 443, &context);
Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, "/?encoding=text", Poco::Net::HTTPMessage::HTTP_1_1);
request.set("origin", "https://www.websocket.org");
Poco::Net::HTTPResponse response;
try
{
Poco::Net::WebSocket webSocket(Client, request, response);
std::string str = "Hello!";
char receiveBuff[256];
int len = webSocket.sendFrame(str.data(), str.size(), Poco::Net::WebSocket::FRAME_TEXT);
std::cout << "Sent bytes " << len << std::endl;
int flags = 0;
int rlen = webSocket.receiveFrame(receiveBuff, 256, flags);
std::cout << "Received bytes " << rlen << std::endl;
std::cout << receiveBuff << std::endl;
webSocket.close();
}
catch (std::exception &e)
{
std::cout << "Exception " << e.what();
}
但我使用此代码获得SSL Exception。 请问有人帮帮我吗? 感谢