Results 1 to 8 of 8

Thread: Problem encountered in http server implementation

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2010
    Posts
    46
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Symbian S60
    Thanks
    3
    Thanked 1 Time in 1 Post

    Default Re: Problem encountered in http server implementation

    I am testing this server using a Firefox and the server running on the same machine. What is the appropriate should the server wait for the request to arrive ?

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanked 268 Times in 268 Posts
    Wiki edits
    20

    Default Re: Problem encountered in http server implementation

    Quote Originally Posted by ada10 View Post
    What is the appropriate should the server wait for the request to arrive ?
    That's the wrong question to ask, and here's why:
    You can never know.

    You can set a time out though to, for example, 10 seconds.

    Here are the two techniques to deal with the data:
    1. Asynchronous, or non-blocking. This is event driven. Every time data becomes available, the socket will post an event resulting in a signal (the readyRead signal)
    If you connect a slot to this signal, you can use readLine, or any of the other read functions. In the mean time, the socket will do nothing except checking the buffers and it will not block the event queue.

    2. Synchronous, or blocking. This is not event driven. The socket just waits for data te become available. It blocks the event queue and can almost only be used in threads.
    Use the waitFor...() functions.

    Suggestion: Do not use threads and certainly not the blocking functions unless you absolutely need to.

  3. #3
    Join Date
    May 2010
    Posts
    46
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Symbian S60
    Thanks
    3
    Thanked 1 Time in 1 Post

    Exclamation Re: Problem encountered in http server implementation

    I used both the methods as you mentioned. In the asynchronous method I tried, the code looked like this -

    Qt Code:
    1. clientConnection = tcpServer->nextPendingConnection();
    2.  
    3. connect(clientConnection, SIGNAL(disconnected()),
    4. clientConnection, SLOT(deleteLater()));
    5.  
    6. connect( clientConnection, SIGNAL(readyRead()),
    7. this, SLOT(readClient()) );
    To copy to clipboard, switch view to plain text mode 

    where the readClient() slot implementation is as shown -

    Qt Code:
    1. void serverwindow::readClient()
    2. {
    3. QTcpSocket* clientSocket = (QTcpSocket*)sender();
    4.  
    5. //pass this socket to a new thread which send some data to client
    6. }
    To copy to clipboard, switch view to plain text mode 

    Here as I obtain some data on socket, I used to spawn a new thread with the socket reference as a parameter to the thread. This caused huge problems because that socket reference could not be "moved" to another thread. So this was the issue I faced with the asynchronous method.

    So I used th synchronous method with waitForReadyRead() method with some parameter ( which is not the way code should be written; I understand ).
    Certainly I know, the asynch method is better, but I could not find a solution to the above problem . If you could provide some solution to this, I would be happy to incorporate into my code.

  4. #4
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanked 268 Times in 268 Posts
    Wiki edits
    20

    Default Re: Problem encountered in http server implementation

    I'll try to write an example later today.

Similar Threads

  1. Sample of Http server
    By Lele in forum Qt Programming
    Replies: 2
    Last Post: 30th November 2010, 23:43
  2. Qt Http implementation
    By ada10 in forum Newbie
    Replies: 6
    Last Post: 11th August 2010, 23:36
  3. Http server : send images
    By fitzy in forum Qt Programming
    Replies: 1
    Last Post: 2nd November 2009, 12:04
  4. mutithread in http-server
    By chuengchuenghq in forum Qt Programming
    Replies: 1
    Last Post: 8th June 2008, 00:24
  5. Build an HTTP server
    By the_bis in forum Qt Programming
    Replies: 4
    Last Post: 30th March 2007, 07:36

Tags for this Thread

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.