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!