Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Winsock TCP Client disconnect

Winsock TCP Client disconnect

Scheduled Pinned Locked Moved C / C++ / MFC
sysadminquestioncomtoolshelp
5 Posts 3 Posters 0 Views 1 Watching
  • 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.
  • E Offline
    E Offline
    Eytukan
    wrote on last edited by
    #1

    I have a question. Are these same? 1. Close the client application window. [ Closes the stream ], (Server gets out of the below block) do { n=recv(client,buff,MAX_BUFF_SIZE,0); if(n==SOCKET_ERROR ) { break; } }while() 2. UnPlug the client's network cable. [should close the stream?] , server never gets notified? it never happens. WTF??? :wtf: :confused: I'm not able to detect the latter one. Please help. If the n/w cable is unplugged, the stream would be broken and it should fire a sock exception right?:~


    --[:jig:]-- [My Current Status] Link2006 wrote:Let's take it outside of CP Jeremy : Please don't.I would love to see this.I'm making the popcorn already.

    F C 2 Replies Last reply
    0
    • E Eytukan

      I have a question. Are these same? 1. Close the client application window. [ Closes the stream ], (Server gets out of the below block) do { n=recv(client,buff,MAX_BUFF_SIZE,0); if(n==SOCKET_ERROR ) { break; } }while() 2. UnPlug the client's network cable. [should close the stream?] , server never gets notified? it never happens. WTF??? :wtf: :confused: I'm not able to detect the latter one. Please help. If the n/w cable is unplugged, the stream would be broken and it should fire a sock exception right?:~


      --[:jig:]-- [My Current Status] Link2006 wrote:Let's take it outside of CP Jeremy : Please don't.I would love to see this.I'm making the popcorn already.

      F Offline
      F Offline
      Frank K
      wrote on last edited by
      #2

      Hi, the value from SOCKET_ERROR is -1 if you unplug the network recv will be return 0 Change your code to do { n=recv(client,buff,MAX_BUFF_SIZE,0); if(1 > n) { break; } }while(); HTH Frank

      E 1 Reply Last reply
      0
      • F Frank K

        Hi, the value from SOCKET_ERROR is -1 if you unplug the network recv will be return 0 Change your code to do { n=recv(client,buff,MAX_BUFF_SIZE,0); if(1 > n) { break; } }while(); HTH Frank

        E Offline
        E Offline
        Eytukan
        wrote on last edited by
        #3

        Nope! :( It doesn't work. The disconnection is not detected. Please help.


        --[:jig:]-- [My Current Status] Link2006 wrote:Let's take it outside of CP Jeremy : Please don't.I would love to see this.I'm making the popcorn already.

        1 Reply Last reply
        0
        • E Eytukan

          I have a question. Are these same? 1. Close the client application window. [ Closes the stream ], (Server gets out of the below block) do { n=recv(client,buff,MAX_BUFF_SIZE,0); if(n==SOCKET_ERROR ) { break; } }while() 2. UnPlug the client's network cable. [should close the stream?] , server never gets notified? it never happens. WTF??? :wtf: :confused: I'm not able to detect the latter one. Please help. If the n/w cable is unplugged, the stream would be broken and it should fire a sock exception right?:~


          --[:jig:]-- [My Current Status] Link2006 wrote:Let's take it outside of CP Jeremy : Please don't.I would love to see this.I'm making the popcorn already.

          C Offline
          C Offline
          cmk
          wrote on last edited by
          #4

          TCP does _not_ maintain a connection, it only maintains information about the connection. Unplugging the cable merely prevents data from moving. You need to implement a ping or timeout type feature in your protocol if you want to be notified if/when the cable is unplugged. See: http://tangentsoft.net/wskfaq/newbie.html#abnormalclose[^]

          ...cmk Save the whales - collect the whole set

          E 1 Reply Last reply
          0
          • C cmk

            TCP does _not_ maintain a connection, it only maintains information about the connection. Unplugging the cable merely prevents data from moving. You need to implement a ping or timeout type feature in your protocol if you want to be notified if/when the cable is unplugged. See: http://tangentsoft.net/wskfaq/newbie.html#abnormalclose[^]

            ...cmk Save the whales - collect the whole set

            E Offline
            E Offline
            Eytukan
            wrote on last edited by
            #5

            Thanks for the link!! I just stopped tussling with the issue. Implementing a sensor now ;)


            --[:jig:]-- [My Current Status] Link2006 wrote:Let's take it outside of CP Jeremy : Please don't.I would love to see this.I'm making the popcorn already.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups