Results 1 to 2 of 2

Thread: QTcpSocket help

  1. #1

    Default QTcpSocket help

    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!

  2. #2
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTcpSocket help

    I think you are overcomplicating things. Check out the sendMessage function in the Network chat example.

Similar Threads

  1. Challenging QTcpSocket reliability problem
    By Raccoon29 in forum Qt Programming
    Replies: 3
    Last Post: 13th January 2009, 10:38
  2. array of pointers to QtcpSocket
    By gQt in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 16th June 2008, 09:15
  3. QTcpServer & QTcpSocket questions...
    By jxmot in forum Qt Programming
    Replies: 2
    Last Post: 24th April 2008, 21:38
  4. QTcpSocket and libssh2 ...
    By sandros in forum Qt Programming
    Replies: 6
    Last Post: 21st November 2007, 22:34
  5. Strange QTcpSocket behavior (debugged with Ethereal)
    By mdecandia in forum Qt Programming
    Replies: 23
    Last Post: 28th May 2007, 20:44

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.