PDA

View Full Version : QTcpSocket help



tsd-charlie
6th August 2009, 16:10
I am simply trying to send a message to a server. The server works so there is no issue there. Can someone tell me what is wrong with the following code?


socket = new QTcpSocket;
socket->connectToHost("localhost",6578);

QByteArray block;
QDataStream out(&block, QIODevice::WriteOnly);
out.setVersion(QDataStream::Qt_4_1);
out << quint16(0) << QString("helloServer");
out.device()->seek(0);
out << quint16(block.size() - sizeof(quint16));

socket->write(block);

Sockets are normally trivial but QT is proving to be a nightmare!

franz
6th August 2009, 19:40
I think you are overcomplicating things. Check out the sendMessage function in the Network chat example (http://doc.trolltech.com/4.5/network-network-chat-connection-cpp.html).