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. How to check if TCP/IP connection is active with a device

How to check if TCP/IP connection is active with a device

Scheduled Pinned Locked Moved Visual Basic
sysadminjsontutorial
3 Posts 2 Posters 2 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.
  • S Offline
    S Offline
    sohaib_a
    wrote on last edited by
    #1

    Hey.. I really at my wits end on this. I have a device that i connect to through TCP/IP using an api function call. Because there could be cases where maybe the router/switch restarted or the network went down or something and if this happens then the device should connect automatically again. I need a to check the the connection status of the device,whether it is connected to application or not so then i can reconnect automatically. I did something like this

    Dim information As TcpConnectionInformation
    For Each information In IPGlobalProperties.GetIPGlobalProperties.GetActiveTcpConnections
    If (information.RemoteEndPoint.Address.ToString = readerIp) Then
    state = CInt(information.State)
    End If
    Next

    However this updates the state only after i manually disconnect the device.It the i pull the cable out and plug it back in it still show the same state. Is there another way to this,to check where a connection is..(not like ping) but if there is an active connection between the device and pc.

    N 1 Reply Last reply
    0
    • S sohaib_a

      Hey.. I really at my wits end on this. I have a device that i connect to through TCP/IP using an api function call. Because there could be cases where maybe the router/switch restarted or the network went down or something and if this happens then the device should connect automatically again. I need a to check the the connection status of the device,whether it is connected to application or not so then i can reconnect automatically. I did something like this

      Dim information As TcpConnectionInformation
      For Each information In IPGlobalProperties.GetIPGlobalProperties.GetActiveTcpConnections
      If (information.RemoteEndPoint.Address.ToString = readerIp) Then
      state = CInt(information.State)
      End If
      Next

      However this updates the state only after i manually disconnect the device.It the i pull the cable out and plug it back in it still show the same state. Is there another way to this,to check where a connection is..(not like ping) but if there is an active connection between the device and pc.

      N Offline
      N Offline
      N a v a n e e t h
      wrote on last edited by
      #2

      AFAIK, ping[^] is the efficient way for this. Just ping the device and if you are getting acknowledgement, consider it as active. :)

      Navaneeth How to use google | Ask smart questions

      S 1 Reply Last reply
      0
      • N N a v a n e e t h

        AFAIK, ping[^] is the efficient way for this. Just ping the device and if you are getting acknowledgement, consider it as active. :)

        Navaneeth How to use google | Ask smart questions

        S Offline
        S Offline
        sohaib_a
        wrote on last edited by
        #3

        i know but ping will only tell if the device is connected to the network..it will not tell me if there is an active connection(ie that there is some data flow between the device & pc). For instance the device is connected to my application(i can ping it as well)...however if i pull out the cable and plug it in back again..i can still ping it...but it isn't connected to my application anymore...so the ping check is not enough for this..it wont tell me if it is connected or not..is there some way to do this with sockets and ports?

        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