我尝试通过TCP套接字在QT4应用程序(MyApp)和
Cayuga
(用C++编写)。
现在,MyApp正在向Cayuga发送一些数据,但没有收到任何数据。
void MyApp::init()
QTcpServer *m_server;
QTcpSocket *clientConnection;
//Open socket for transmission
m_server = new QTcpServer(this);
if (!m_server->listen(QHostAddress::Any, m_port)) {
//Error handling
return;
}
connect(m_server, SIGNAL(newConnection()), this, SLOT(startSend()));
void MyApp::startSend()
{
clientConnection = m_server->nextPendingConnection();
}
书写在此处完成:
QByteArray block;
QDataStream out(&block, QIODevice::WriteOnly);
out.setVersion(QDataStream::Qt_4_0);
out << (quint16)0;
out << s;
out.device()->seek(0);
out << (quint16)(block.size() - sizeof(quint16));
clientConnection->write(block);
clientConnection->flush();
我的导师建议,如果我不能让外部库(cudb)与QTcpSockets一起工作,就使用它。这感觉不对,这就是为什么我希望你对我的问题有一个更好的答案。