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#
  4. Network programming

Network programming

Scheduled Pinned Locked Moved C#
sysadmintutorial
10 Posts 5 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.
  • A Offline
    A Offline
    AlexPizzano
    wrote on last edited by
    #1

    Say i have a server running and several client connected to this server. How to program 1)to detect when a client on purpose power down his PC without closing the connection 2)the client's pc hang causing connection to server be disconnected Thanks in advance

    L L J T 4 Replies Last reply
    0
    • A AlexPizzano

      Say i have a server running and several client connected to this server. How to program 1)to detect when a client on purpose power down his PC without closing the connection 2)the client's pc hang causing connection to server be disconnected Thanks in advance

      L Offline
      L Offline
      Laddie
      wrote on last edited by
      #2

      One possible way is to keep some table to track the last activity time of each client. If it is more than some acceptable window we could assume there is something went wrong with the client.

      Thanks Laddie Kindly rate if the answer was helpful

      A 1 Reply Last reply
      0
      • L Laddie

        One possible way is to keep some table to track the last activity time of each client. If it is more than some acceptable window we could assume there is something went wrong with the client.

        Thanks Laddie Kindly rate if the answer was helpful

        A Offline
        A Offline
        AlexPizzano
        wrote on last edited by
        #3

        what will be the best timing to consider a connection has broken

        L 1 Reply Last reply
        0
        • A AlexPizzano

          Say i have a server running and several client connected to this server. How to program 1)to detect when a client on purpose power down his PC without closing the connection 2)the client's pc hang causing connection to server be disconnected Thanks in advance

          L Offline
          L Offline
          Le centriste
          wrote on last edited by
          #4

          loke6258038 wrote:

          to detect when a client on purpose power down his PC without closing the connection

          There is no way to detect a client connection dropped without trying to contact it. If you write both client and server, you could implement some sort of "ping" or "heartbeat" functionality.

          L 1 Reply Last reply
          0
          • A AlexPizzano

            Say i have a server running and several client connected to this server. How to program 1)to detect when a client on purpose power down his PC without closing the connection 2)the client's pc hang causing connection to server be disconnected Thanks in advance

            J Offline
            J Offline
            jithen_dt
            wrote on last edited by
            #5

            When you are closing the connection i.e when the user at the client closes the application call a function and indicate the server that the client is closing normally, on the form close method (if it is a winform) communicate to the server saying forced application close. You need to handle form close carefully because even under normal application close form close method gets triggered (this can be handled).

            1 Reply Last reply
            0
            • A AlexPizzano

              what will be the best timing to consider a connection has broken

              L Offline
              L Offline
              Laddie
              wrote on last edited by
              #6

              It is a matter of what your application does...You will have to figure it out but taking into consideration the the frequencey in which the client communicates to the server.

              Thanks Laddie Kindly rate if the answer was helpful

              1 Reply Last reply
              0
              • L Le centriste

                loke6258038 wrote:

                to detect when a client on purpose power down his PC without closing the connection

                There is no way to detect a client connection dropped without trying to contact it. If you write both client and server, you could implement some sort of "ping" or "heartbeat" functionality.

                L Offline
                L Offline
                Laddie
                wrote on last edited by
                #7

                But the contacting the client from the server will not work if they are in different network where the ports are opened from only one side.Which will probably the typical case.

                Thanks Laddie Kindly rate if the answer was helpful

                L 1 Reply Last reply
                0
                • L Laddie

                  But the contacting the client from the server will not work if they are in different network where the ports are opened from only one side.Which will probably the typical case.

                  Thanks Laddie Kindly rate if the answer was helpful

                  L Offline
                  L Offline
                  Le centriste
                  wrote on last edited by
                  #8

                  If you are concerned with the client dropping the connection, this means that once the connection is opened, you can talk to the client. I don't know the protocol you use, but I suspect it is custom. So, in your communication protocol, you could add a call where the server asks the client if he is still there after some idle time.

                  1 Reply Last reply
                  0
                  • A AlexPizzano

                    Say i have a server running and several client connected to this server. How to program 1)to detect when a client on purpose power down his PC without closing the connection 2)the client's pc hang causing connection to server be disconnected Thanks in advance

                    T Offline
                    T Offline
                    The Nightcoder
                    wrote on last edited by
                    #9

                    Hi, In order to catch all cases, I would suggest a heartbeat function (as was already suggested). Some details (drawn from specs I've encountered interfacing with various industrial PLC systems): - If your client sessions don't use persistent TCP connections (if you are using an HTTP request for each transaction, for example), you're correct in noting that you can't contact the client from the server gratuitously. In that case, have the client contact the server with a dummy message with a specific interval (unless it has already talked to the server during the interval) and let the server invalidate sessions that haven't been heard from in, say, twice that interval. - If you do use persistent TCP connections (that stay open for the duration of the client session) you can contact the clients from the server (you can write to the socket from either direction as long as it's open). You could then send an "are you alive?"-message to clients you hadn't heard from in a while - you will get an exception if the TCP/IP stack has given up on the connection, a response if not and the client is alive, no response if the client is dead but the TCP/IP stack hasn't realized it yet. The benefit of this is that you can tune the timer intervals on the server without having to change or inform the clients. Reasonable interval would be application specific, but beware of swamping the server with keep-alives if you could have a lot of clients. One crane controller protocol I use requires keepalives be sent each minute (by both ends) and any party that hasn't heard anything for two minutes closes and gives up on the connection (if it's the client that gives up, it starts attempting to reconnect to the server - this also has a timeout and will be repeated indefinitely, as the protocol is built for stuff that should be connected at all times). Persistent TCP connections are used here. Useful?

                    -- Peter

                    L 1 Reply Last reply
                    0
                    • T The Nightcoder

                      Hi, In order to catch all cases, I would suggest a heartbeat function (as was already suggested). Some details (drawn from specs I've encountered interfacing with various industrial PLC systems): - If your client sessions don't use persistent TCP connections (if you are using an HTTP request for each transaction, for example), you're correct in noting that you can't contact the client from the server gratuitously. In that case, have the client contact the server with a dummy message with a specific interval (unless it has already talked to the server during the interval) and let the server invalidate sessions that haven't been heard from in, say, twice that interval. - If you do use persistent TCP connections (that stay open for the duration of the client session) you can contact the clients from the server (you can write to the socket from either direction as long as it's open). You could then send an "are you alive?"-message to clients you hadn't heard from in a while - you will get an exception if the TCP/IP stack has given up on the connection, a response if not and the client is alive, no response if the client is dead but the TCP/IP stack hasn't realized it yet. The benefit of this is that you can tune the timer intervals on the server without having to change or inform the clients. Reasonable interval would be application specific, but beware of swamping the server with keep-alives if you could have a lot of clients. One crane controller protocol I use requires keepalives be sent each minute (by both ends) and any party that hasn't heard anything for two minutes closes and gives up on the connection (if it's the client that gives up, it starts attempting to reconnect to the server - this also has a timeout and will be repeated indefinitely, as the protocol is built for stuff that should be connected at all times). Persistent TCP connections are used here. Useful?

                      -- Peter

                      L Offline
                      L Offline
                      Laddie
                      wrote on last edited by
                      #10

                      Thanks Peter..It is a good note.

                      Thanks Laddie Kindly rate if the answer was helpful

                      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