Home AMX User Forum AMX General Discussion

Checking state of IP connection

Hello,

i would like to know the best way to detect if an IP connection is open or closed with Netlinx. I mean:

At one section of code, i use the IP_CLIENT_OPEN keyword to open an IP connection at a specific local port of the master.
At other section of code, i use the IP_CLIENT_CLOSE keyword to close that IP connection.
And at a third section of code i need to know in which state are the IP connection, if it is open or closed.

Do you know any other way to check it, apart of using a boolean variable? Or is it the only available method?

Thanks for your help!

Comments

  • viningvining Posts: 4,368
    Morgoz wrote:
    Do you know any other way to check it, apart of using a boolean variable? Or is it the only available method?
    Yeah you pretty much need to set a variable in the on & off_line events. There's no IP_PORT_ACTIVE kind of a function.
  • I would recommend a 3-state variable, to track e.g.
    0 - offline
    2- IP Client/Server Open in progress
    1 - Connected

    While in state 2, no additional Open should be done to that port.
    If the IP connect failed (~ 1 minute timeout from TCP handling) you'll get an ONERROR event. At this point, reset the variable to state 0.
  • viningvining Posts: 4,368
    Marc Scheibein wrote:
    I would recommend a 3-state variable, to track e.g.
    I'll take your 3 and raise you 5 or 6!

    I actually take it a step further and create a few other states like disable so depending on what type of onerror return I get I'll disable as opposed to auto re-connect. The TX & RX are just in case I want blinking lights for feedback, often I won't.

    Pending is for the time between IP_CLIENT_OPEN and the online event triggering just to prevent other things from happening like the auto re-connect.

    Device ready is for certain devices that reguire log in or other procedures before they'll respond to additional commands.

    DEFINE_CONSTANT //CLIENT CONNECTIONS 
    
    #DEFINE IP_CLIENT_CONSTANTS
    
    IP_CLIENT_DISABLED	= 0 ;
    IP_CLIENT_DISCO		= 1 ;
    IP_CLIENT_PENDING	= 2 ;
    IP_CLIENT_CONNECTED	= 3 ;
    IP_CLIENT_DEVICE_READY	= 4 ;
    IP_CLIENT_RX_DATA	= 5 ;
    IP_CLIENT_TX_DATA	= 6 ;
    
    DEFINE_CONSTANT //SERVER CONNECTIONS
    
    #DEFINE IP_SERVER_CONSTANTS
    
    IP_SERVER_DISABLED	= 0 ;
    IP_SERVER_STOPPED	= 1 ;
    IP_SERVER_READY		= 2 ;
    IP_SERVER_CLIENT_ON	= 3 ;
    IP_SERVER_RX_DATA	= 4 ;
    IP_SERVER_TX_DATA	= 5 ;
    
Sign In or Register to comment.