Results 1 to 5 of 5

Thread: Server is not reading from client

  1. #1
    Join Date
    Jan 2006
    Posts
    185
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Server is not reading from client

    I have this very simple server and I would like it to be able to read any data from a client.

    the .h file
    **********************************
    Qt Code:
    1. #ifndef CLIENTSERVER_H
    2. #define CLIENTSERVER_H
    3.  
    4. #include <QMainWindow>
    5.  
    6. class QByteArray;
    7. class QTcpSocket;
    8. class QTcpServer;
    9.  
    10.  
    11. class ClientServer : public QMainWindow
    12. {
    13. Q_OBJECT
    14. private:
    15. QTextBrowser * textBrowser;
    16. QByteArray * byteArray;
    17. QTcpSocket * tcpSocket;
    18. QTcpServer * tcpServer;
    19.  
    20. public:
    21. ClientServer();
    22.  
    23. signals:
    24.  
    25. public slots:
    26. void readData();
    27.  
    28. };
    29.  
    30. # endif
    To copy to clipboard, switch view to plain text mode 
    ***************************************


    the .cpp file
    ***************************************
    Qt Code:
    1. #include <QTextBrowser>
    2. #include <QByteArray>
    3. #include <QTcpSocket>
    4. #include <QTcpServer>
    5. #include "clientserver.h"
    6.  
    7. ClientServer::ClientServer()
    8. {
    9. textBrowser = new QTextBrowser(this);
    10. tcpServer = new QTcpServer();
    11. tcpSocket = new QTcpSocket();
    12. setCentralWidget(textBrowser);
    13. setFixedSize(500,500);
    14. show();
    15.  
    16. if(tcpServer->listen(QHostAddress("localhost"), quint16(33333)))
    17. textBrowser->append("ClientServer is listening");
    18.  
    19. tcpSocket->setSocketDescriptor(tcpServer->socketDescriptor());
    20. connect(tcpSocket, SIGNAL(readyRead()), this, SLOT(readData()));
    21.  
    22. }
    23.  
    24. void ClientServer::readData()
    25. {
    26. textBrowser->append("Ready to read");
    27. }
    To copy to clipboard, switch view to plain text mode 
    ************************************************** ***

    I cannot even get to the readData() function.

    Why?
    How can I make it read from a client?
    Last edited by wysota; 30th November 2006 at 14:23. Reason: missing [code] tags

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Server is not reading from client

    You should connect to signal QTcpServer::newConnection() and then use QTcpServer::nextPendingConnection() to get the socket whose signal QTcpSocket::readyRead() you are interested of. See the examples shipped with Qt or the Simple Chat example in our wiki.
    J-P Nurmi

  3. #3
    Join Date
    Jan 2006
    Posts
    185
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Server is not reading from client

    I read now from the client (browser), but I cannot write to the browser. When I write to a telnet window, then the message is shown there, but the browser does not display the html message.

    How can I solve it ?

  4. #4
    Join Date
    Jan 2006
    Posts
    185
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Server is not reading from client

    I don't want to make my code to complex...

    I just want to know:

    1. How can the server know that the browser has finished sending all its data ?

  5. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Server is not reading from client

    You don't know unless you provide some kind of "end-of-message" mark from the other side. Read this thread.
    J-P Nurmi

Similar Threads

  1. Sql Server cannot retrieve data from select
    By Atomino in forum Qt Programming
    Replies: 10
    Last Post: 7th September 2006, 16:37
  2. Replies: 1
    Last Post: 5th July 2006, 14:12
  3. The server cannot write to the client. Why?
    By probine in forum Newbie
    Replies: 12
    Last Post: 24th March 2006, 17:14
  4. synching client readings to server output
    By OnionRingOfDoom in forum Qt Programming
    Replies: 14
    Last Post: 28th January 2006, 18:15
  5. Reading from TCP Socket crashes program
    By OnionRingOfDoom in forum Qt Programming
    Replies: 26
    Last Post: 27th January 2006, 19:32

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.