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.ReceiveTimeOut Problem

Socket.ReceiveTimeOut Problem

Scheduled Pinned Locked Moved C#
help
9 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.
  • L Offline
    L Offline
    lnmca
    wrote on last edited by
    #1

    Hi All, When I set the ReceiveTimeOut of Socket to some milliseconds then Socket throws the timeout Exception while the period expires and the problem is that then Socket is disconnected therefore i am unable to send and receive again with this socket. I want that it waites for sometime for receiving but after elapsing the time,it should not be disconnected so that i can use it again n again.. Plz help...Its urgent. Best Regards, Lalit Narayan

    P P 2 Replies Last reply
    0
    • L lnmca

      Hi All, When I set the ReceiveTimeOut of Socket to some milliseconds then Socket throws the timeout Exception while the period expires and the problem is that then Socket is disconnected therefore i am unable to send and receive again with this socket. I want that it waites for sometime for receiving but after elapsing the time,it should not be disconnected so that i can use it again n again.. Plz help...Its urgent. Best Regards, Lalit Narayan

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

      From MSDN: The ReceiveTimeout property determines the amount of time that the Read method will block until it is able to receive data. This time is measured in milliseconds. If the time-out expires before Read successfully completes, TcpClient throws a IOException. There is no time-out by default. Read more here[^]. Kind regards,

      The only programmers that are better C# programmers, are those who look like this -> :bob:

      :java: Programm3r My Blog: ^_^

      L 1 Reply Last reply
      0
      • P Programm3r

        From MSDN: The ReceiveTimeout property determines the amount of time that the Read method will block until it is able to receive data. This time is measured in milliseconds. If the time-out expires before Read successfully completes, TcpClient throws a IOException. There is no time-out by default. Read more here[^]. Kind regards,

        The only programmers that are better C# programmers, are those who look like this -> :bob:

        :java: Programm3r My Blog: ^_^

        L Offline
        L Offline
        lnmca
        wrote on last edited by
        #3

        But when the socket throws exception ,socket is disconnected...this creates the problem 4 me,plz give the solution so that the socket should not be disconnected. Best Regards, Lalit Narayan

        P 1 Reply Last reply
        0
        • L lnmca

          But when the socket throws exception ,socket is disconnected...this creates the problem 4 me,plz give the solution so that the socket should not be disconnected. Best Regards, Lalit Narayan

          P Offline
          P Offline
          Programm3r
          wrote on last edited by
          #4

          I think that is what happens when the time-out period is exceeded, the Receive method will throw a SocketException. Have you tried catching the exception, checking whether the socket is still connected (see here[^]), if not try to reconnect...

          The only programmers that are better C# programmers, are those who look like this -> :bob:

          :java: Programm3r My Blog: ^_^

          L 1 Reply Last reply
          0
          • P Programm3r

            I think that is what happens when the time-out period is exceeded, the Receive method will throw a SocketException. Have you tried catching the exception, checking whether the socket is still connected (see here[^]), if not try to reconnect...

            The only programmers that are better C# programmers, are those who look like this -> :bob:

            :java: Programm3r My Blog: ^_^

            L Offline
            L Offline
            lnmca
            wrote on last edited by
            #5

            Hi, Actually i am working on Server Side,the connection requests comes from the Client Side,i can not reconnect to the Client through Socket.... The Server has TCP Listener on its own side,that waits for the Connection Request from the Client and make the Socket after Accepts the request. Best Regards, Lalit Narayan

            P 1 Reply Last reply
            0
            • L lnmca

              Hi, Actually i am working on Server Side,the connection requests comes from the Client Side,i can not reconnect to the Client through Socket.... The Server has TCP Listener on its own side,that waits for the Connection Request from the Client and make the Socket after Accepts the request. Best Regards, Lalit Narayan

              P Offline
              P Offline
              Programm3r
              wrote on last edited by
              #6

              As far as my understanding of TCP/IP clients and server(s) goes; it is the client initiates the connection. So, if the client disconnect in any way from the server, when it is the clients 'responsibility' to reconnect to the server. Kind regards,

              The only programmers that are better C# programmers, are those who look like this -> :bob:

              :java: Programm3r My Blog: ^_^

              L 1 Reply Last reply
              0
              • P Programm3r

                As far as my understanding of TCP/IP clients and server(s) goes; it is the client initiates the connection. So, if the client disconnect in any way from the server, when it is the clients 'responsibility' to reconnect to the server. Kind regards,

                The only programmers that are better C# programmers, are those who look like this -> :bob:

                :java: Programm3r My Blog: ^_^

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

                Hi, The Client Side Code is written in C at Embeded Side n it takes some time to show the status "Disconnected" this creates the problem 4 me,they find the state of Socket "Connected" while it is disconnected at Server Side... Plz do the needful. Thanks and Regards, Lalit Narayam

                P 1 Reply Last reply
                0
                • L lnmca

                  Hi, The Client Side Code is written in C at Embeded Side n it takes some time to show the status "Disconnected" this creates the problem 4 me,they find the state of Socket "Connected" while it is disconnected at Server Side... Plz do the needful. Thanks and Regards, Lalit Narayam

                  P Offline
                  P Offline
                  Programm3r
                  wrote on last edited by
                  #8

                  Well it seems to me that the embedded side needs some works?! :^)

                  lnmca wrote:

                  The Client Side Code is written in C at Embeded Side n it takes some time to show the status "Disconnected" this creates the problem 4 me,they find the state of Socket "Connected" while it is disconnected at Server Side

                  You cannot build on something if it is not working correctly.. X|

                  The only programmers that are better C# programmers, are those who look like this -> :bob:

                  :java: Programm3r My Blog: ^_^

                  1 Reply Last reply
                  0
                  • L lnmca

                    Hi All, When I set the ReceiveTimeOut of Socket to some milliseconds then Socket throws the timeout Exception while the period expires and the problem is that then Socket is disconnected therefore i am unable to send and receive again with this socket. I want that it waites for sometime for receiving but after elapsing the time,it should not be disconnected so that i can use it again n again.. Plz help...Its urgent. Best Regards, Lalit Narayan

                    P Offline
                    P Offline
                    Paulo Zemek
                    wrote on last edited by
                    #9

                    Well, I think you can't do that. Imagine the situation: Server starts reading. Client starts sending. But, for some reason, the connection is VERY slow. Server then receives the time-out (imagine it does not disconnect). The server then asks for more data... but, the client is still sending the old-data. So, the server must now wait for what? The old data? The new data? How will it differentiate one data from the other? I think the fact the connection is closed is on purpose. If you want, I think you may NOT use the ReceiveTimeOut. Instead, create another thread to call "abort" in the reading thread if it takes too long, so the connection will not be aborted, but I don't really know what will happen with the data in this case. Also, depending on your requirements, it's possible to use UDP to receive the data.

                    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