Results 1 to 2 of 2

Thread: mutithread in http-server

  1. #1
    Join Date
    Jun 2008
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Exclamation

    I wanna develop a http server using muti-thread,during the communication connections,which some must keep-alive.
    how the plan it.
    or someone give me the source code with explainatons..

    in addition,
    see the defination if class timeserver
    Qt Code:
    1. void timeserver:::incomingConnection(socketdescriptor,0);
    2. {
    3.  
    4. TimeThread *thread = new TimeThread(socketDescriptor,0);
    5. connect(thread,SIGNAL(finished()),dlg,SLOT(showResult()),Qt::QueuedConnection);
    6. connect(thread,SIGNAL(finished()),thread,SLOT(deletelater()),Qt::DirectConnection);
    7.  
    8. thread->start();
    9.  
    10. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. defination of class TimeThread
    2. void TimeThread::run()
    3. {
    4. QTcpSocket socket = new QTcpSocket;
    5. if(!socket->setSocketDescriptor(socketDescriptor))
    6. {
    7. return;
    8.  
    9.  
    10. }
    11.  
    12. socket->write("aaa");
    13. connect(socket,SIGNAL(readyRead()),this,SLOT(read()));// never exec the read() function when the client has sent the data, why?
    14.  
    15.  
    16.  
    17.  
    18.  
    19. }
    20.  
    21. void TimeThread::read()
    22. {
    23. qDebug() << "reading data";
    24.  
    25. }
    To copy to clipboard, switch view to plain text mode 

    as u see,I can only send data to client, how can i receive data from client,where should the slot function set?//
    Qt Code:
    1. connect(socket,SIGNAL(readyRead()),this,SLOT(read()));
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 6th June 2008 at 07:24. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: mutithread in http-server

    You have to start the event loop in the thread to make QTcpSocket work. See QThread::exec().

Similar Threads

  1. How to download any file through ftp server
    By thomasjoy in forum Qt Programming
    Replies: 1
    Last Post: 24th July 2007, 01:23
  2. How to ping a server ?
    By Nyphel in forum Newbie
    Replies: 2
    Last Post: 23rd April 2007, 11:27
  3. Build an HTTP server
    By the_bis in forum Qt Programming
    Replies: 4
    Last Post: 30th March 2007, 07:36
  4. How a server can write "Hello" to a browser ?
    By probine in forum Qt Programming
    Replies: 2
    Last Post: 1st December 2006, 14:43
  5. synching client readings to server output
    By OnionRingOfDoom in forum Qt Programming
    Replies: 14
    Last Post: 28th January 2006, 18:15

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.