Click here to Skip to main content
15,881,898 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to use secure websocket by using C++ to connect echo.websocket.org.
It works in javascript at https://www.websocket.org/echo.html[^]

My solution is to use Poco libraries and my code looks like following.

C#
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);

//      Poco::JSON::Object JSON_Subscribe;
//      JSON_Subscribe.set("type", "suscribe");
//      JSON_Subscribe.set("product_id", "BTC-USD");

//      std::ostringstream stream;
//      JSON_Subscribe.stringify(stream);
    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();
}



But I get SSL Exception with this code.
Can anybody help me, please?
Thanks
Posted
Comments
Dark Darkling 17-Mar-16 4:05am    
Could you please provide more details on SSL exception?

Possibly you don't have OpenSSL installed on your system. Or maybe OpenSSL is incorrectly installed.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900