Skip to content

Instantly share code, notes, and snippets.

@ElectricImpSampleCode
Last active March 25, 2019 12:41
Show Gist options
  • Save ElectricImpSampleCode/6ab77a58dfc711216982 to your computer and use it in GitHub Desktop.
Save ElectricImpSampleCode/6ab77a58dfc711216982 to your computer and use it in GitHub Desktop.
A code snippet showing when and how to trap unexpected disconnection events.
// EARLY CALL CODE
server.setsendtimeoutpolicy(RETURN_ON_ERROR, WAIT_TIL_SENT, 30.0);
// GLOBALS
local disconnectedFlag = false;
local disconnectedCount = 0;
// FUNCTIONS
function mainProgramLoop() {
// We'll fill this in below
}
function disconnectionHandler(reason) {
// Function called automatically if the agent link is lost
if (reason != SERVER_CONNECTED) disconnectedFlag = true;
}
// START OF RUNTIME
server.onunexpecteddisconnect(disconnectionHandler);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment