Results 1 to 6 of 6

Thread: QTcpServer - how to refuse incomming connection

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QTcpServer - how to refuse incomming connection

    You can delete the QTcpServer object and thus stop if from listening.

    Cheers,
    _

  2. #2
    Join Date
    Jan 2014
    Posts
    76
    Thanks
    17
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QTcpServer - how to refuse incomming connection

    No, I can not delete QTcpServer, because I must operate with other accepted connections.
    I want only say to the next incomming connection, that they should wait because server is overloaded, maybe something like this:

    Qt Code:
    1. void Server::incomingConnection(int socketId)
    2. {
    3.  
    4. if( canAcceptConnection() )
    5. addClient(socketId);
    6. else {
    7. QTcpSocket *socket = new QTcpSocket(this);
    8. socket->setSocketDescriptor(socketId);
    9. socket->write("Server is overloaded, try again later...\r\n");
    10. socket->close();
    11. socket->deleteLater();
    12. }
    13.  
    14. }
    To copy to clipboard, switch view to plain text mode 

    that is a good idea?

  3. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QTcpServer - how to refuse incomming connection

    Quote Originally Posted by atomic View Post
    No, I can not delete QTcpServer, because I must operate with other accepted connections.
    The QTcpServer is not involved in already accepted connections, so if you reparent the QTcpSockets to a different object they won't be affected by the server's deletion.

    Quote Originally Posted by atomic View Post
    I want only say to the next incomming connection, that they should wait because server is overloaded, maybe something like this:
    This is of course something entirely different than not accepting connections.
    In comment #3 you complained about clients getting connected.

    Quote Originally Posted by atomic View Post
    that is a good idea?
    If you have a protocol between server and client then it might even make sense to specify such a "return later" exchange.
    E.g. HTTP's 503 status

    Cheers,
    _

  4. The following user says thank you to anda_skoa for this useful post:

    atomic (20th August 2015)

Similar Threads

  1. Qt 4.8.3 and ptlib 2.10.8 refuse to work together
    By BigFastAndrey in forum Qt Programming
    Replies: 0
    Last Post: 5th December 2012, 08:54
  2. [QTcpServer] Lost Connection
    By Markus_AC in forum Qt Programming
    Replies: 2
    Last Post: 12th January 2012, 12:08
  3. Replies: 0
    Last Post: 1st August 2011, 13:06
  4. Replies: 5
    Last Post: 23rd May 2010, 01:09
  5. Drag incomming localurl !=linux not work kde
    By patrik08 in forum Qt Programming
    Replies: 6
    Last Post: 11th December 2006, 15:23

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.