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. Socket is suddenly closed

Socket is suddenly closed

Scheduled Pinned Locked Moved C#
comadobesysadminhelpquestion
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.
  • H Offline
    H Offline
    Haim Nachum
    wrote on last edited by
    #1

    Hi. I have a chat site (http://www.pitput.com) that connects user via socket connections. I have in the client side a flash object that opens a connection to a port in my server. In the server i have a service that is listening to that port in an async matter. All is working fine except when i talk to someone after an unknown period of time(about couple of minutes) the server is closing my connection and i get an error in the server : " A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond". I dont know how exactly the tcp socket works. does it checking for "live" connection every couple of seconds? how does it decide when to close the connection? Im pretty sure that the close operation is not coming from the client side. Thanks.

    P J B 3 Replies Last reply
    0
    • H Haim Nachum

      Hi. I have a chat site (http://www.pitput.com) that connects user via socket connections. I have in the client side a flash object that opens a connection to a port in my server. In the server i have a service that is listening to that port in an async matter. All is working fine except when i talk to someone after an unknown period of time(about couple of minutes) the server is closing my connection and i get an error in the server : " A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond". I dont know how exactly the tcp socket works. does it checking for "live" connection every couple of seconds? how does it decide when to close the connection? Im pretty sure that the close operation is not coming from the client side. Thanks.

      P Offline
      P Offline
      Peter_in_2780
      wrote on last edited by
      #2

      Wireshark is your friend. Get it started, do your thing, and when you get the error, stop Wireshark and look through the trace. It's probably worth saving the trace then applying an IP filter to see only the traffic of interest. You will be able to see which end failed to respond (and, importantly, the packet that did not get a response). Cheers, Peter

      Software rusts. Simon Stephenson, ca 1994.

      1 Reply Last reply
      0
      • H Haim Nachum

        Hi. I have a chat site (http://www.pitput.com) that connects user via socket connections. I have in the client side a flash object that opens a connection to a port in my server. In the server i have a service that is listening to that port in an async matter. All is working fine except when i talk to someone after an unknown period of time(about couple of minutes) the server is closing my connection and i get an error in the server : " A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond". I dont know how exactly the tcp socket works. does it checking for "live" connection every couple of seconds? how does it decide when to close the connection? Im pretty sure that the close operation is not coming from the client side. Thanks.

        J Offline
        J Offline
        jschell
        wrote on last edited by
        #3

        Haim Nachum wrote:

        I dont know how exactly the tcp socket works. does it checking for "live" connection every couple of seconds?

        No.

        Haim Nachum wrote:

        how does it decide when to close the connection? Im pretty sure that the close operation is not coming from the client side.

        The connection is not not closed. You are getting a timeout failure.

        Haim Nachum wrote:

        and i get an error in the server :

        You get that error in the server? I would expect that from a client. Clients connect to servers not the other way around.

        1 Reply Last reply
        0
        • H Haim Nachum

          Hi. I have a chat site (http://www.pitput.com) that connects user via socket connections. I have in the client side a flash object that opens a connection to a port in my server. In the server i have a service that is listening to that port in an async matter. All is working fine except when i talk to someone after an unknown period of time(about couple of minutes) the server is closing my connection and i get an error in the server : " A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond". I dont know how exactly the tcp socket works. does it checking for "live" connection every couple of seconds? how does it decide when to close the connection? Im pretty sure that the close operation is not coming from the client side. Thanks.

          B Offline
          B Offline
          BobJanova
          wrote on last edited by
          #4

          TCP operates a timeout if no packets are sent for some time, because this is usually a sign that the connection has been lost. The time varies but is usually around 30s to a couple of minutes. If you want to maintain a connection despite no user interaction, you need to send 'keep-alive' packets or 'pings' every few seconds (one every 20s should be enough) to keep the connection open. However, remember that if you do this, idle connections will never time out and you can run out of server sockets if too many people leave your app open, so you then should have some client code that logs out and closes the socket after a longer inactive time (30 mins or so).

          J T 2 Replies Last reply
          0
          • B BobJanova

            TCP operates a timeout if no packets are sent for some time, because this is usually a sign that the connection has been lost. The time varies but is usually around 30s to a couple of minutes. If you want to maintain a connection despite no user interaction, you need to send 'keep-alive' packets or 'pings' every few seconds (one every 20s should be enough) to keep the connection open. However, remember that if you do this, idle connections will never time out and you can run out of server sockets if too many people leave your app open, so you then should have some client code that logs out and closes the socket after a longer inactive time (30 mins or so).

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

            BobJanova wrote:

            TCP operates a timeout if no packets are sent for some time, because this is usually a sign that the connection has been lost.

            TCP does not do that.

            BobJanova wrote:

            you want to maintain a connection despite no user interaction, you need to send 'keep-alive' packets or 'pings' every few seconds (one every 20s should be enough) to keep the connection open

            You do that because the server or firewall requires it - not TCP.

            BobJanova wrote:

            However, remember that if you do this, idle connections will never time out and you can run out of server sockets if too many people leave your app open, so you then should have some client code that logs out and closes the socket after a longer inactive time (30 mins or so).

            That of course is an architecture problem. If you server is going to respect keep-alives then it must exist in an enterprise that doesn't expect an unlimited number of client all with persistent connections. One alternative to that possibility is to close even connections that are in use after a given time period. Or require a connect/message/close protocol like http.

            B 1 Reply Last reply
            0
            • J jschell

              BobJanova wrote:

              TCP operates a timeout if no packets are sent for some time, because this is usually a sign that the connection has been lost.

              TCP does not do that.

              BobJanova wrote:

              you want to maintain a connection despite no user interaction, you need to send 'keep-alive' packets or 'pings' every few seconds (one every 20s should be enough) to keep the connection open

              You do that because the server or firewall requires it - not TCP.

              BobJanova wrote:

              However, remember that if you do this, idle connections will never time out and you can run out of server sockets if too many people leave your app open, so you then should have some client code that logs out and closes the socket after a longer inactive time (30 mins or so).

              That of course is an architecture problem. If you server is going to respect keep-alives then it must exist in an enterprise that doesn't expect an unlimited number of client all with persistent connections. One alternative to that possibility is to close even connections that are in use after a given time period. Or require a connect/message/close protocol like http.

              B Offline
              B Offline
              BobJanova
              wrote on last edited by
              #6

              TCP does not do that.

              I thought I'd read that, but if it is not TCP, then it is the operating system, because if you open a TCP connection to your own server and send nothing in either direction, at some point it will get closed.

              J 1 Reply Last reply
              0
              • B BobJanova

                TCP operates a timeout if no packets are sent for some time, because this is usually a sign that the connection has been lost. The time varies but is usually around 30s to a couple of minutes. If you want to maintain a connection despite no user interaction, you need to send 'keep-alive' packets or 'pings' every few seconds (one every 20s should be enough) to keep the connection open. However, remember that if you do this, idle connections will never time out and you can run out of server sockets if too many people leave your app open, so you then should have some client code that logs out and closes the socket after a longer inactive time (30 mins or so).

                T Offline
                T Offline
                toploader
                wrote on last edited by
                #7

                bob hi, im sorry im not going through the right channels but i am trying to ask you a question in regards to the game lobby,,,,, please contact me at lb4262002@yahoo.co.uk thanks alan (member name TOPLOADER)

                B 1 Reply Last reply
                0
                • T toploader

                  bob hi, im sorry im not going through the right channels but i am trying to ask you a question in regards to the game lobby,,,,, please contact me at lb4262002@yahoo.co.uk thanks alan (member name TOPLOADER)

                  B Offline
                  B Offline
                  BobJanova
                  wrote on last edited by
                  #8

                  Start a question thread on the article.

                  T 1 Reply Last reply
                  0
                  • B BobJanova

                    Start a question thread on the article.

                    T Offline
                    T Offline
                    toploader
                    wrote on last edited by
                    #9

                    i am sorry i am a new member and am not sure how to start a new thread on the subject, if i could see a new thread tab i would do it sorry. please be patient with me as i have tried to send you a message 3 times and although we are not talking about why i want to speak to you at least i am speaking to you which is a step forward. please can you giude me to the new thread link, many thanks alan.

                    1 Reply Last reply
                    0
                    • B BobJanova

                      TCP does not do that.

                      I thought I'd read that, but if it is not TCP, then it is the operating system, because if you open a TCP connection to your own server and send nothing in either direction, at some point it will get closed.

                      J Offline
                      J Offline
                      jschell
                      wrote on last edited by
                      #10

                      BobJanova wrote:

                      I thought I'd read that, but if it is not TCP, then it is the operating system, because if you open a TCP connection to your own server and send nothing in either direction, at some point it will get closed.

                      No it won't. And it isn't the "OS". OSes have what is typically called a 'IP Stack' which implements IP/TCP/UPD/ICMP. And they implement it based on the RFCs associated with those protocols. Application use an API to access that. And assume that the stack implementation is actually correctly implementing the RFCs. If you are seeing something close connections then it is as I said: the server, the client or something in between like a firewall.

                      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