Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    SO_KEEPALIVE usocket option ?

    Scheduled Pinned Locked Moved Discussion
    8 Posts 4 Posters 2.4k Views 4 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M Offline
      mkharibalaji
      last edited by

      Hi Team,
      Is SO_KEEPALIVE usocket option available ?

      //Hari

      A 1 Reply Last reply Reply Quote 0
      • A Offline
        abilio @mkharibalaji
        last edited by

        @mkharibalaji, not at this moment. Do you specifically need it?

        1 Reply Last reply Reply Quote 0
        • M Offline
          mkharibalaji
          last edited by

          @abilio Yes ! I have ported pynats NATS.io protocol to work with micropython which would be added to GitHub soon as i am testing it.I need the feature of SO_KEEPALIVE and TCP_NODELAY such that the library is complete or else i can only release with the feature being ported later.

          1 Reply Last reply Reply Quote 0
          • O Offline
            obertuckerz112
            last edited by

            This should also work right.

            1 Reply Last reply Reply Quote 0
            • M Offline
              mkharibalaji
              last edited by

              @abilio When can we expect this feature ?

              1 Reply Last reply Reply Quote 0
              • W Offline
                Wembly
                last edited by Wembly

                This feature would be cool to have. In many situations you cannot have a socket opened more than 2 hours without it...
                Socket will be dropped without any notification. I have implemented a simple timer that sends a packet every hour as a temporary fix.

                A 1 Reply Last reply Reply Quote 0
                • A Offline
                  abilio
                  last edited by abilio

                  @mkharibalaji, KEEPALIVE seems to be supported by the LwIP library that is being internally used by the LoPy/WiPy2, but yet some work is needed in the MicroPython side to take this parameter. Right now we're dealing with completing the support of all important features of the boards, improving free memory, and later we will have a cycle for improvements like this one.

                  1 Reply Last reply Reply Quote 0
                  • A Offline
                    abilio @Wembly
                    last edited by abilio

                    @Wembly, to add my two cents as a sockets user, in the past I tried to use KEEPALIVE for this kind of applications, and fount it to be unreliable (I don't wanna say useless).

                    For example, the default behavior for all Linux distros I've seen is not to start sending KEEPALIVES until 2 hours of inactivity (that's the shortest recommended interval). Yet, some small devices like home routers will start silently closing connections way before that, so you can easily have more than an hour 45 minutes of quietness without actually realizing the connection was dropped.

                    The specific reasons not to rely on SO_KEEPALIVE, at least how I read them, are mentioned here: https://tools.ietf.org/html/rfc1122#page-101 (section 4.2.3.6).

                    This interval MUST be configurable and MUST default to no less than two hours.

                    If a keep-alive mechanism is implemented it MUST NOT interpret failure to respond to any specific probe as a dead connection.

                    The TCP specification does not include a keep-alive mechanism because it could: (1) cause perfectly good connections to break during transient Internet failures; (2) consume unnecessary bandwidth ("if no one is using the connection, who cares if it is still good?"); and (3) cost money for an Internet path that charges for packets.

                    Whenever I've dealt with this situation (knowing if the other end is still there), I implement it pretty much the same way you did. I'm by no means a protocol expert, so if you have important reasons for the need of this feature, I can try push it higher on the list.

                    1 Reply Last reply Reply Quote 1

                    Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                    Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                    With your input, this post could be even better 💗

                    Register Login
                    • 1 / 1
                    • First post
                      Last post

                    Pycom on Twitter

                    Pycom