How to detect RST flag with QTcpSocket



  • I am currently working on a network program. We know that when the remote host disconnects from you, it might be a normal disconnection or a reset. If it is a reset, the RST flag in the TCP packet is set. I want to know how to judge whether a disconnection is a normal one or a reset (using QTcpSocket when disconnected() is emitted). Additionally, if I want to send a packet with RST flag set, what should I do? Emit abort()?


  • Qt Champions 2016

    @yvbbrjdr
    Hello,

    I want to know how to judge whether a disconnection is a normal one or a reset (using QTcpSocket when disconnected() is emitted)

    I don't think that's possible with QTcpSocket.

    Additionally, if I want to send a packet with RST flag set, what should I do?

    Why should you want to do that in the first place?

    Emit abort()?

    abort() is not a signal and you don't emit signals from outside of the objects themselves, but yes, you call the abort() method. It should do what you want.

    Kind regards.


  • Moderators

    @yvbbrjdr

    to add to @kshegunov
    You can check using state and error() giving you SocketState and SocketError



  • @koahnig Thanks. So which exactly of the element in QAbstractSocket::SocketError represents reset?

    There are
    ConnectionRefusedError
    RemoteHostClosedError
    HostNotFoundError
    SocketAccessError
    SocketResourceError
    SocketTimeoutError
    DatagramTooLargeError
    NetworkError
    AddressInUseError
    SocketAddressNotAvailableError
    UnsupportedSocketOperationError
    ProxyAuthenticationRequiredError
    SslHandshakeFailedError
    UnfinishedSocketOperationError
    ProxyConnectionRefusedError
    ProxyConnectionClosedError
    ProxyConnectionTimeoutError
    ProxyNotFoundError
    ProxyProtocolError
    OperationError
    SslInternalError
    SslInvalidUserDataError
    TemporaryError
    UnknownSocketError


  • Moderators

    @yvbbrjdr

    @koahnig said:

    to add to @kshegunov
    You can check using state and error() giving you SocketState and SocketError

    You need to follow the links already in the post before. There you find explanations much better than I can briefly summarize. The reset flag is part of a lower layer in TCP/IP. As already lined out by @kshegunov what for do you require to that there has been exactly this flag sent?
    I fear when you are using Qt wrappings for TCP comms, this might be completely out of your control, because issued by the lower level routines not part of Qt.



  • @koahnig Actually I am working on a TCP relay server. When server resets the connection, I have to reset the connection to the client, too.


  • Moderators

    @yvbbrjdr
    OK, that is explaining your need. ;)
    Sometimes "simple" users got stuck with some thoughts of their needs, but actually do not need those details.

    I am not sure, if you will receive response from here. This is typically more user oriented.
    The developer's email list might be better for such details.


  • Qt Champions 2016

    @yvbbrjdr
    As I said, I'm pretty sure Qt doesn't expose these low-level details, but posting your question on the the mail group, as @koahnig suggested, certainly can't hurt.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.