我在qt c ++中为Kaazing Gateway编写聊天客户端。我用的是QTcpSocket。我调用connectToHost并且连接正常。但是当我调用socket写入功能时,连接断开。怎么了?如何向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();
答案 0 :(得分:0)
如果您按照这两个步骤操作,您应该可以毫无问题地连接到网关!