0

I write chat client for Kaazing Gateway in qt c++. I use QTcpSocket. I call connectToHost and connection is ok. But when i call socket write function connection is disconnected. What wrong? How write message to kaazing server?

//connect to server
QTcpSocket _sok = new QTcpSocket(this);
connect(_sok, SIGNAL(connected()), this, SLOT(onSokConnected()));
connect(_sok, SIGNAL(disconnected()), this, SLOT(onSokDisconnected()));

_sok->connectToHost("localhost", 8000); //after this line run onSokConnected()


// write message
    QByteArray  arrBlock;
    QDataStream out(&arrBlock, QIODevice::WriteOnly);
    out.setVersion( QDataStream::Qt_4_5 );
    out << quint16(0) <<sometext;

    out.device()->seek(0);
    out << quint16(arrBlock.size() - sizeof(quint16));

    _sok->write(arrBlock);  // after this line run onSokDisconnected()
    _sok->flush();
Tatyana
  • 9
  • 1
  • What kind of message do you get when disconnected ? Maybe you already use this, but if not, you can try to use QTcpSocket::SocketState and originals signals of QTcpSocket state for further details – samubreizhizel May 08 '16 at 22:00
  • You don't use websocket. Websocket class is QWebSocket and please read somehting on it http://doc.qt.io/qt-5/qtwebsockets-index.html – Alexander V May 09 '16 at 05:25

1 Answers1

0
  • 1st thing you have to use the QT Websocket libraries, you can find an example here.
  • 2nd if you have already downloaded the gateway from kaazing.com/download , it comes already configured with an echo service, you need to put that URI (ws://localhost:8000/echo) in main.cpp.

If you follow these 2 steps you should be able to connect to the gateway without any problems!

zahariaca
  • 1
  • 3