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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Detecting Server (Socket) Disconnect?

Detecting Server (Socket) Disconnect?

Scheduled Pinned Locked Moved C / C++ / MFC
workspacehtmlcomsysadmindebugging
4 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.
  • G Offline
    G Offline
    gvanto
    wrote on last edited by
    #1

    After following the great tutorial on here: http://tldp.org/LDP/LG/issue74/tougher.html[^] sources in folder here: http://www.sharedigest.com/SocketClientServer.zip[^] I've managed to get the client and server talking to each other. This is for an setup whereby data will be transmitted to my client via telnet from a remote server, and, according to them, I need to configure the client in such a way that it checks if the server dies and automatically attempts to reconnect after some (pre-specified) time period. Currently, when I kill the server, I get ALOT of '' received by the client, continuously ... (output shown below, main routine shown below output) I was wondering if there's a way to detect that the connection from the server's been lost, and consequently attempt to reconnect and keep listening for incoming messages? Help much appreciated! gvanto socket newbie Server: pacific@mainbox:~/workspace/SocketClientServer/Debug$ ./SocketClientServer 0 starting server ... Hello server from client. Please enter string to send: hello back to client Please enter string to send: another message Please enter string to send: one more Please enter string to send: //here i kill the server using ctrl+c Client: pacific@mainbox:~/workspace/SocketClientServer/Debug$ ./SocketClientServer 1 starting client ... Sending hello server msg ... Listening ... We received this response from the server: "hello back to client" Listening ... We received this response from the server: "another message" Listening ... We received this response from the server: "one more" Listening ... We received this response from the server: //AFter server killed, FLOOD of incoming BLANK messages received by client "" Listening ... We received this response from the server: "" Listening ... We received this response from the server: "" Listening ... We received this response from the server: "" Listening ... We received this response from the server: "" Listening ... We received this response from the server: "" Listening ... We received this response from the server: "" Listening ... We received this response from the server: "" Listening ... We received this respons

    S E 2 Replies Last reply
    0
    • G gvanto

      After following the great tutorial on here: http://tldp.org/LDP/LG/issue74/tougher.html[^] sources in folder here: http://www.sharedigest.com/SocketClientServer.zip[^] I've managed to get the client and server talking to each other. This is for an setup whereby data will be transmitted to my client via telnet from a remote server, and, according to them, I need to configure the client in such a way that it checks if the server dies and automatically attempts to reconnect after some (pre-specified) time period. Currently, when I kill the server, I get ALOT of '' received by the client, continuously ... (output shown below, main routine shown below output) I was wondering if there's a way to detect that the connection from the server's been lost, and consequently attempt to reconnect and keep listening for incoming messages? Help much appreciated! gvanto socket newbie Server: pacific@mainbox:~/workspace/SocketClientServer/Debug$ ./SocketClientServer 0 starting server ... Hello server from client. Please enter string to send: hello back to client Please enter string to send: another message Please enter string to send: one more Please enter string to send: //here i kill the server using ctrl+c Client: pacific@mainbox:~/workspace/SocketClientServer/Debug$ ./SocketClientServer 1 starting client ... Sending hello server msg ... Listening ... We received this response from the server: "hello back to client" Listening ... We received this response from the server: "another message" Listening ... We received this response from the server: "one more" Listening ... We received this response from the server: //AFter server killed, FLOOD of incoming BLANK messages received by client "" Listening ... We received this response from the server: "" Listening ... We received this response from the server: "" Listening ... We received this response from the server: "" Listening ... We received this response from the server: "" Listening ... We received this response from the server: "" Listening ... We received this response from the server: "" Listening ... We received this response from the server: "" Listening ... We received this respons

      S Offline
      S Offline
      Stuart Dootson
      wrote on last edited by
      #2

      Go back to Beej's networking guid that you were looking at a few days ago - that says this in the section about recv

      Wait! recv() can return 0. This can mean only one thing: the remote side has closed the connection on you! A return value of 0 is recv()'s way of letting you know this has occurred.

      [edit]I'd modify the ClientSocket class to do something like throw an exception on getting a return value of zero from recv.[/edit]

      Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

      G 1 Reply Last reply
      0
      • G gvanto

        After following the great tutorial on here: http://tldp.org/LDP/LG/issue74/tougher.html[^] sources in folder here: http://www.sharedigest.com/SocketClientServer.zip[^] I've managed to get the client and server talking to each other. This is for an setup whereby data will be transmitted to my client via telnet from a remote server, and, according to them, I need to configure the client in such a way that it checks if the server dies and automatically attempts to reconnect after some (pre-specified) time period. Currently, when I kill the server, I get ALOT of '' received by the client, continuously ... (output shown below, main routine shown below output) I was wondering if there's a way to detect that the connection from the server's been lost, and consequently attempt to reconnect and keep listening for incoming messages? Help much appreciated! gvanto socket newbie Server: pacific@mainbox:~/workspace/SocketClientServer/Debug$ ./SocketClientServer 0 starting server ... Hello server from client. Please enter string to send: hello back to client Please enter string to send: another message Please enter string to send: one more Please enter string to send: //here i kill the server using ctrl+c Client: pacific@mainbox:~/workspace/SocketClientServer/Debug$ ./SocketClientServer 1 starting client ... Sending hello server msg ... Listening ... We received this response from the server: "hello back to client" Listening ... We received this response from the server: "another message" Listening ... We received this response from the server: "one more" Listening ... We received this response from the server: //AFter server killed, FLOOD of incoming BLANK messages received by client "" Listening ... We received this response from the server: "" Listening ... We received this response from the server: "" Listening ... We received this response from the server: "" Listening ... We received this response from the server: "" Listening ... We received this response from the server: "" Listening ... We received this response from the server: "" Listening ... We received this response from the server: "" Listening ... We received this respons

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

        It simply sucks to go through the junk. Please remove it. Also, to answer your question, based on my guess, I think you are not talking about a natural disconnect between server & client. TCP is connection oriented, when one breaks it , you should get an exception. But there's one exception, when there's a slight network disruption, the server actually loses it's connection with client, but it acts to be there alive. The client gets notified but the server don't. even the send function wouldn't convey us anything.That's a problem. There we need to set up a ping mechanism. The server asks "Are you all alive".. the clients say "Yes we are". If few client's don't say, they are actually out. We need to remove them from association with server. I don't remember the scenario so clearly. I did these long before. I'm not sure If I'm right :P. A couple of years before I replied to the same question with a more vivid answer. lol memory's fading. :sigh:


        OK,. what country just started work for the day ? The ASP.NET forum is flooded with retarded questions. -Christian Graus Best wishes to Rexx[^]

        1 Reply Last reply
        0
        • S Stuart Dootson

          Go back to Beej's networking guid that you were looking at a few days ago - that says this in the section about recv

          Wait! recv() can return 0. This can mean only one thing: the remote side has closed the connection on you! A return value of 0 is recv()'s way of letting you know this has occurred.

          [edit]I'd modify the ClientSocket class to do something like throw an exception on getting a return value of zero from recv.[/edit]

          Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

          G Offline
          G Offline
          gvanto
          wrote on last edited by
          #4

          Thanks alot, think the recv() == 0 should do the trick. I've set it up to be reconnecting every somany seconds, when it does it keeps listening. Many thanks again guys, onto threads now! :-) (multiple clientsockets within class)

          Find Your Dream Job in Australia, Free! http://www.WebCV.com.au

          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