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. Visual Basic
  4. TCPClient.Connect Timeout?

TCPClient.Connect Timeout?

Scheduled Pinned Locked Moved Visual Basic
hardwaredata-structurestestingbeta-testingquestion
4 Posts 3 Posters 1 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.
  • R Offline
    R Offline
    RGVChris
    wrote on last edited by
    #1

    Hi, I am working on some code which is designed to communicate with up to 16 embedded devices over a LAN with eventual real time data display and logging. Using a series of UDP broadcasts, a rectangular array is populated with the ip addresses of the units. This process is repeated at a regular intervals and the array compared to it's previous state to find any units which have not responded to the UDP broadcast sequence, implying that either communication has failed for serious reasons or a packet has simply been dropped. Any lost IPs are then passed to a function which attempts TCP to each in turn, in order to get confirmation of any communication problems. However I have found in testing that a TCP connection that fails can take up to 30 seconds to return an exception, so in a worst case situation it could take 8 minutes for my app to notice that all 16 units have gone offline. From long research it seems to me that my only solution is to rewrite large amounts of code to use a sockets implementation instead of a TCPClient, but can anyone think of a way which would save a large rewrite?:confused:

    D A 2 Replies Last reply
    0
    • R RGVChris

      Hi, I am working on some code which is designed to communicate with up to 16 embedded devices over a LAN with eventual real time data display and logging. Using a series of UDP broadcasts, a rectangular array is populated with the ip addresses of the units. This process is repeated at a regular intervals and the array compared to it's previous state to find any units which have not responded to the UDP broadcast sequence, implying that either communication has failed for serious reasons or a packet has simply been dropped. Any lost IPs are then passed to a function which attempts TCP to each in turn, in order to get confirmation of any communication problems. However I have found in testing that a TCP connection that fails can take up to 30 seconds to return an exception, so in a worst case situation it could take 8 minutes for my app to notice that all 16 units have gone offline. From long research it seems to me that my only solution is to rewrite large amounts of code to use a sockets implementation instead of a TCPClient, but can anyone think of a way which would save a large rewrite?:confused:

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      RGVChris wrote:

      However I have found in testing that a TCP connection that fails can take up to 30 seconds to return an exception, so in a worst case situation it could take 8 minutes for my app to notice that all 16 units have gone offline.

      So you're checking each unit, one at a time, using the same thread?? Why not create a seperate thread, per unit, to verify this? Then, all of the tests run concurrently.

      RGVChris wrote:

      but can anyone think of a way which would save a large rewrite?

      No matter what, you're going to end up rewriting a large chunk of code, it's just a matter of how large.

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
           2006, 2007, 2008

      1 Reply Last reply
      0
      • R RGVChris

        Hi, I am working on some code which is designed to communicate with up to 16 embedded devices over a LAN with eventual real time data display and logging. Using a series of UDP broadcasts, a rectangular array is populated with the ip addresses of the units. This process is repeated at a regular intervals and the array compared to it's previous state to find any units which have not responded to the UDP broadcast sequence, implying that either communication has failed for serious reasons or a packet has simply been dropped. Any lost IPs are then passed to a function which attempts TCP to each in turn, in order to get confirmation of any communication problems. However I have found in testing that a TCP connection that fails can take up to 30 seconds to return an exception, so in a worst case situation it could take 8 minutes for my app to notice that all 16 units have gone offline. From long research it seems to me that my only solution is to rewrite large amounts of code to use a sockets implementation instead of a TCPClient, but can anyone think of a way which would save a large rewrite?:confused:

        A Offline
        A Offline
        alx n
        wrote on last edited by
        #3

        How about: Dim client As New TcpClient(IpAddress, Port) client.SendTimeout = 5000

        alex_nel

        R 1 Reply Last reply
        0
        • A alx n

          How about: Dim client As New TcpClient(IpAddress, Port) client.SendTimeout = 5000

          alex_nel

          R Offline
          R Offline
          RGVChris
          wrote on last edited by
          #4

          alex_nel wrote:

          How about: Dim client As New TcpClient(IpAddress, Port) client.SendTimeout = 5000

          That was what I thought, but it seems that only affects the timeout of messages being sent, not the initial timeout at [client.connect] :( I dont understand why MS didnt provide a client.connecttimeout property...

          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