Home AMX User Forum MODPEDIA - The Public Repository of Modules for Everyone

IP Device Comm

Its simple but I thought it might be useful for people new to IP comm

This module will properly handle all of your IP devices.
Keeping them online and reporting errors.

Comments

  • truetrue Posts: 307
    This is bound to spit out lots of errors when latency is high or an IP is offline.
  • true wrote: »
    This is bound to spit out lots of errors when latency is high or an IP is offline.

    If the device is offline there will be an error report once a second but of course you could extend that by simply changing the timeline.

    Are you suggesting a better way or just pointing out the error reporting?
  • truetrue Posts: 307
    Yes, there is a better way - don't create the timeline and only process connect events at startup, in offline, and in onerror, when you are both not connected and not connecting and therefore can actually successfully attempt a connection.

    Your method also has the property that a connection attempt, on the first try, will take at minimum the time of your timeline time before an attempt to reconnect is made. Further retries will take at most as long as the timeline time, rather than immediately when possible or after some cascaded delay (after X failures, wait Y time before reconnects). My AppleTV module takes both of these into consideration (the latter mostly for prevention of console error spamming).
  • a_riot42a_riot42 Posts: 1,624
    I don't follow why you need to 'keep trying'. You already know when every state of the port occurs, offline, online, in error, receiving data, etc so I don't understand the need to 'try'. ip_client_open always returns 0 unless there is an error. If you want to send something to the port, open it and send something and if it errors out deal with it accordingly. Why try when you can just do?
    Paul
  • OK thanks for all the input.
  • JasonSJasonS Posts: 229
    I wrote an IP comm template that uses Send_Commands to configure connection timeout and automatic connection. Most IP devices that I have encountered will automatically drop a connection after a certain amount of idle time. My module has a "Connection Timeout" value that you can set from the main program, if this value is > 0 the module will close the connection after the amount of time specified if the Transmit Buffer is empty. If new commands are added to the Transmit Buffer the Module will automatically reconnect to the IP device. If the connection Timeout is set to 0, the module will immediately attempt to reconnect to the IP device whenever the connection is dropped. If the connection attempt fails the module will then periodically attempt to reconnect, I don't remember how often it tries.

    I don't trust timelines for continuous running (I have had issues in the past, timelines mysteriously stopping after 6 months), so I use the "GET_TIMER" function in mainline to get the current system timer value and add an offset to it for my response timeouts and reconnect timeouts in my comm modules.
  • IP device comms - Thanks for the file Chevyman78

    @Chevyman78: Thanks for the file there. Very programmer spirited of you to share a code that should help to make life easier for your fellow programmers. I have just downloaded it to try, as my own IP coding could be better.

    // rant starts
    @EveryoneElse who has thrown constructive criticism at Chevyman78 – if your methods are better or your code more efficient, great. Please share them and help all of us improve. Im happy to learn new coding methods, but at least Chevyman78 has been good enough to provide a code example that we call all look at and use to learn. Your comments so far may be aimed as helpful, but do smack a bit of just criticizing someone who is genuinely trying to help the AMX programming community. Lets not put people off the altruistic idea of actually helping fellow programmers

    // end rant
  • elshoutelshout Posts: 9
    I agree with Andrew. It has been a year and Chevyman78 is the only one who has posted any code. Thanks for the effort Chevyman78!
    JasonS wrote: »
    I wrote an IP comm template that uses Send_Commands to configure connection timeout and automatic connection. Most IP devices that I have encountered will automatically drop a connection after a certain amount of idle time. My module has a "Connection Timeout" value that you can set from the main program, if this value is > 0 the module will close the connection after the amount of time specified if the Transmit Buffer is empty. If new commands are added to the Transmit Buffer the Module will automatically reconnect to the IP device. If the connection Timeout is set to 0, the module will immediately attempt to reconnect to the IP device whenever the connection is dropped. If the connection attempt fails the module will then periodically attempt to reconnect, I don't remember how often it tries.

    I don't trust timelines for continuous running (I have had issues in the past, timelines mysteriously stopping after 6 months), so I use the "GET_TIMER" function in mainline to get the current system timer value and add an offset to it for my response timeouts and reconnect timeouts in my comm modules.

    JasonS - do you care to post your code? It sounds like it might work well.
Sign In or Register to comment.