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. what to do after a read from a socket Timeout

what to do after a read from a socket Timeout

Scheduled Pinned Locked Moved C#
question
6 Posts 4 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.
  • M Offline
    M Offline
    manustone
    wrote on last edited by
    #1

    Hi All I am using TcpClient to read from a socket and I set the property ReceiveTimeout to a value let's say 3 seconds. As per documentation, after the read fails because of a Timeout, an IOexception is thrown. After that point, each time I call ReadLine the exception is systematically thrown again and again. What to do to reset the Timeout value or to renable the reading from a socket with no worry? I reset a new value for ReceiveTimeout but it doesn't work. Do you know what to do?

    D F E 3 Replies Last reply
    0
    • M manustone

      Hi All I am using TcpClient to read from a socket and I set the property ReceiveTimeout to a value let's say 3 seconds. As per documentation, after the read fails because of a Timeout, an IOexception is thrown. After that point, each time I call ReadLine the exception is systematically thrown again and again. What to do to reset the Timeout value or to renable the reading from a socket with no worry? I reset a new value for ReceiveTimeout but it doesn't work. Do you know what to do?

      D Offline
      D Offline
      David Knechtges
      wrote on last edited by
      #2

      Don't know if this will help you or not..... I have a UDP client based application. We were having troubles reconnecting the computers when one of the network cards would go down for some reason. What I ended up doing was checking for exceptions, and depending on the exceptions, I would then try closing/reopening the socket. Maybe this is what you need to do. You should also probably test for the case I had which was to have the apps communicating, and then disable the network adapter and reenable it.

      1 Reply Last reply
      0
      • M manustone

        Hi All I am using TcpClient to read from a socket and I set the property ReceiveTimeout to a value let's say 3 seconds. As per documentation, after the read fails because of a Timeout, an IOexception is thrown. After that point, each time I call ReadLine the exception is systematically thrown again and again. What to do to reset the Timeout value or to renable the reading from a socket with no worry? I reset a new value for ReceiveTimeout but it doesn't work. Do you know what to do?

        F Offline
        F Offline
        freakyit
        wrote on last edited by
        #3

        i don't think the exception is thrown because of the ReceiveTimeout.. if nothings availible to read the buffer would be empty and that would may by throw an exception.. try to check before reading using the property if (client.DataAvailable > 0) { ... string line = client.ReadLine(); ... }

        M 1 Reply Last reply
        0
        • M manustone

          Hi All I am using TcpClient to read from a socket and I set the property ReceiveTimeout to a value let's say 3 seconds. As per documentation, after the read fails because of a Timeout, an IOexception is thrown. After that point, each time I call ReadLine the exception is systematically thrown again and again. What to do to reset the Timeout value or to renable the reading from a socket with no worry? I reset a new value for ReceiveTimeout but it doesn't work. Do you know what to do?

          E Offline
          E Offline
          Ennis Ray Lynch Jr
          wrote on last edited by
          #4

          A timeout closes the connection. You have to re-establish the connection. Make sure your TcpClient has keepalive set to true, and make sure the server isn't timing out on you. Also, a higher timeout value can help unless there is a major issue with the server timing out, in which case you will just wait longer for the exception.

          Need custom software developed? I do custom programming based primarily on MS tools with an emphasis on C# development and consulting. A man said to the universe: "Sir I exist!" "However," replied the universe, "The fact has not created in me A sense of obligation." --Stephen Crane

          M 1 Reply Last reply
          0
          • F freakyit

            i don't think the exception is thrown because of the ReceiveTimeout.. if nothings availible to read the buffer would be empty and that would may by throw an exception.. try to check before reading using the property if (client.DataAvailable > 0) { ... string line = client.ReadLine(); ... }

            M Offline
            M Offline
            manustone
            wrote on last edited by
            #5

            hi Freakyit thank you very much for this snippet..I didn't know about it Mmstn

            1 Reply Last reply
            0
            • E Ennis Ray Lynch Jr

              A timeout closes the connection. You have to re-establish the connection. Make sure your TcpClient has keepalive set to true, and make sure the server isn't timing out on you. Also, a higher timeout value can help unless there is a major issue with the server timing out, in which case you will just wait longer for the exception.

              Need custom software developed? I do custom programming based primarily on MS tools with an emphasis on C# development and consulting. A man said to the universe: "Sir I exist!" "However," replied the universe, "The fact has not created in me A sense of obligation." --Stephen Crane

              M Offline
              M Offline
              manustone
              wrote on last edited by
              #6

              Thank you very mcuh! I didn't know that! It helps! mnstn

              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