Results 1 to 5 of 5

Thread: receive data from client via QTcpServer

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2010
    Posts
    58
    Qt products
    Qt4
    Platforms
    Windows
    Thanked 2 Times in 2 Posts

    Default Re: receive data from client via QTcpServer

    Quote Originally Posted by tbscope View Post
    You can only read from the socket if there's something to read.
    You try to read a nanosecond after you've send the welcom message. In that time, the client didn't have time to respond.

    Suggestions:
    Qt Code:
    1. void Server::sendWelcomeMessage()
    2. {
    3. typedef QVector<QTcpSocket*> Connections; // <-- Define this at the class level
    4. Connections connections; // This too
    5.  
    6. while (server->hasPendingConnections ()) {
    7. QTcpSocket *client = server->nextPendingConnection();
    8. connect(client, SIGNAL(disconnected()), client, SLOT(deleteLater()));
    9. connect(client, SIGNAL(readyRead()), signalmapper, SLOT(map())); // Signal mapper is defined in the class definition and created in the constructor, see QSignalMapper.
    10. signalmapper->setMapping(client, client);
    11. client->write("Welcome!");
    12. }
    13. connect(signalmapper, SIGNAL(mapped(QObject *)), this, SLOT(clientReadyRead(QObject *)));
    14. }
    15.  
    16. void Server::clientReadyRead(QObject *socket)
    17. {
    18. QTcpSocket *clientSocket = qobject_cast<QTcpSocket *>(socket);
    19.  
    20. clientSocket->read...()
    21. }
    To copy to clipboard, switch view to plain text mode 
    i get this error:
    signalmapper was not declared in this scope

  2. #2
    Join Date
    Aug 2010
    Posts
    58
    Qt products
    Qt4
    Platforms
    Windows
    Thanked 2 Times in 2 Posts

    Default Re: receive data from client via QTcpServer

    nvm, i fixed it myself thx

Similar Threads

  1. Replies: 4
    Last Post: 18th August 2010, 08:13
  2. Replies: 1
    Last Post: 24th March 2010, 08:15
  3. QTCPsocket data corrupt when receive
    By gabizzz in forum Qt Programming
    Replies: 2
    Last Post: 4th March 2010, 17:29
  4. Replies: 14
    Last Post: 27th November 2006, 05:09
  5. Replies: 1
    Last Post: 5th July 2006, 14:12

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
  •  
Qt is a trademark of The Qt Company.