我用 qt c++ 为 Kaazing Gateway 编写聊天客户端。我使用 QTcpSocket。我打电话给 connectToHost 并且连接正常。但是当我调用套接字写入函数时,连接被断开。怎么了?如何将消息写入 kaazing 服务器?
//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();