Click here to Skip to main content
15,891,204 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm new to the Poco Libraries and could use a little help in understanding where my error is. I've been scouring the web for good examples SSL Websocket clients and there doesn't appear to be any.

Here is the code I am currently attempting to debug.
It should open a websocket to the server and subscribe to the service.

Update:
Thanks to HTTPS request in c++ using Poco, I am now getting past the WebSocket Initialization, but I am not seeing a response from the server for the subscribe message.


C++
bool CMAIMarketFeedCoinBaseEngine::ConnectToServer(void)
{
	Poco::Net::initializeSSL();

	Poco::SharedPtr<Poco::Net::InvalidCertificateHandler> ptrHandler = new Poco::Net::AcceptCertificateHandler(false);
    Poco::Net::Context context(Poco::Net::Context::CLIENT_USE, "", "", "", Poco::Net::Context::VERIFY_RELAXED, 9, false, "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
	Poco::Net::SSLManager::instance().initializeClient(0, ptrHandler, &context);

	Poco::Net::HTTPSClientSession Client("ws-feed.exchange.coinbase.com", 443, &context);

    Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, "/wss", Poco::Net::HTTPMessage::HTTP_1_1);
    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 =  stream.str();

		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();
    }

	return true;
}


I get an exception when the websocket is instantiated.
__vfptr 0x5c7080e8 {PocoNetSSLd.dll!const Poco::Net::SSLException::`vftable'} {0x5c6b1622 {PocoNetSSLd.dll!Poco::Net::SSLException::`vector deleting destructor'(unsigned int)}, ...} void * *


C++
bool ConnectToServer(void)
{
	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("ws-feed.exchange.coinbase.com", 443, &context);

    Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, "/", Poco::Net::HTTPMessage::HTTP_1_1);
    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 =  stream.str();

		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();
    }

	return true;
}
Posted
Updated 29-Mar-15 6:48am
v2

1 solution

This would appear to be a Poco error. You will probably get an answer quicker by using the Poc forum at http://pocoproject.org/[^].
 
Share this answer
 
Comments
JackDingler 29-Mar-15 12:51pm    
I was able to get past that error with a bit more code. I have updated the example.

Poco's exception handling could use a bit more information. Throwing generic exceptions on bad pointers in their own code, isn't very helpful.
JackDingler 29-Mar-15 13:05pm    
Thank you for that link Richard.

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