c++ - Qt websockets to connect to Pusher service -
i have javascript snippet connects pusher service need convert c++
<script src="//js.pusher.com/2.2/pusher.min.js" type="text/javascript"></script> <script type="text/javascript"> var pusher = new pusher("cb65d0a7a72cd94adf1f"); var channel = pusher.subscribe("ticker.155"); channel.bind("message", function(data) { //console.log(data); var topbuy = data.trade.topbuy; var topsell = data.trade.topsell; console.log("buy price: ", topbuy.price, "buy quantity:", topbuy.quantity), console.log("sell price: ", topsell.price, "sell quantity:", topsell.quantity); }); </script>
i able bust open connection packet little thought of going on http://i.imgur.com/4iyidlz.png can't seem connection.
socketclass.cpp
#include "socketclass.h" socketclass::socketclass(qobject *parent) : qobject(parent) { } void socketclass::test() { socket = new qtcpsocket(this); connect(socket,signal(connected()), this, slot(connected())); connect(socket,signal(disconnected()), this, slot(disconnected())); connect(socket,signal(readyread()), this, slot(readyread())); connect(socket,signal(byteswritten(qint64)), this, slot(byteswritten(qint64))); qdebug() << "......connecting"; socket->connecttohost("ws.pusherapp.com/app/cb65d0a7a72cd94adf1f?protocol=7&client=js&version=2.2.3&flash=false",80); if(!socket->waitforconnected(1000)) { qdebug() << "error: " << socket->errorstring(); } } void socketclass::connected() { //meat , potatoes goes here qdebug() << "......connected"; //socket->write("head / http/1.0\r\n\r\n\r\n"); socket->event(); } void socketclass::disconnected() { qdebug() << "......disconnected"; } void socketclass::byteswritten (qint64 bytes) { qdebug() << "we wrote: " << bytes; } void socketclass::readyread() { qdebug() << "reading..,,"; qdebug() << socket->readall(); }
socketclass.h
#ifndef socketclass_h #define socketclass_h #include <qdebug> #include <qobject> #include <qtcpsocket> #include <qabstractsocket> class socketclass : public qobject { q_object public: explicit socketclass(qobject *parent = 0); void test(); signals: public slots: void connected(); void disconnected(); void byteswritten (qint64 bytes); void readyread(); private: qtcpsocket *socket; }; #endif // socketclass_h
main.cpp
#include <qcoreapplication> #include "socketclass.h" int main(int argc, char *argv[]) { qcoreapplication a(argc, argv); socketclass mtest; mtest.test(); homecoming a.exec(); }
what proper connection parameters should utilize c++ websockets emulate javascript? trying receive ticker info , assign object or variable.
my qt experience bit old, see won't signals since don't have event loop running. should not utilize waitforconnected
call, should either run a.exec()
, allow take care of pumping events. thing seems weird phone call waitforconnected
, an error still phone call a.exec()
don't signals after (or maybe stopping application after failure?).
c++ qt websocket pusher
No comments:
Post a Comment