Skip to main content

Server Status

When a user logs out from the KOBIL Portal, the application receives a ServerConnectionEvent, indicating a change in server connection status. The application responds by updating the UI to reflect the current status and displays an appropriate alert dialog. The MasterController then triggers a logout and sends a RestartEvent to the application, which handles this event by restarting and updating the UI based on the SDK state. If the SDK state of the RestartEvent is LOGIN_REQUIRED, the application redirects the user to the login screen.

Server Connection Event Flow Diagram

The following diagram illustrates the flow of server connection events and their handling:

Possible connection statuses

In general, there are 2 main connection statuses, and these statuses are known as CONNECTED and DISCONNECTED:

  • CONNECTED indicates that we logged in to SSMS and maintain a session.
  • DISCONNECTED indicates that the session has been terminated, either by the SSMS, or due to a connection failure.

There are four more statuses providing more detailed information, but those are less important:

  • REACHABLE and NOT_REACHABLE: Prior to logging in there possibly is already communication to SSMS. Depending on whether such communication attempts succeed or fail, you get a server connection event informing you on whether the SSMS is REACHABLE or NOT_REACHABLE.
  • CONNECTION_LOST and RECONNECTED: While you are CONNECTED, there is always the potential for a temporary networking issue, so some requests might be lost. If this happens, you get an event with status CONNECTION_LOST and MC SDK automatically retries to send the request that failed (several times). If that succeeds, you get an event with status RECONNECTED. So, these statuses do not strictly require any action as they either refer to a self-curing problem or - if communication keeps failing - the problem will be escalated to a connection event with status DISCONNECTED. In that case you need to take action (by doing a login after a automatic restart completed). However, if you keep getting connection events with statuses CONNECTION_LOST and RECONNECTED, you might want to inform the user that his Internet connection appears to be flaky - most likely due to poor WIFI reception - and that he might experience slowness of the app due to excessive need for retrying to transmit packages and waiting for timeouts.

Finally (for historic completeness), there still are 3 more statuses that are deprecated and should not be used any more:

  • UNDEFINED
  • INVALID_STATE
  • RESTART_ON_NOT_REACHABLE

iOS/Swift

To handle server connection events and respond to changes in the server connection status, implement the receive method to handle incoming KSMServerConnectionEvent instances.

extension ServerModel: KSAsyncEventReceiver {
func receive(_ event: KsEvent, withCompletionHandler completionBlock: ((KsEvent?) -> Void)? = nil) {
if let serverConnectionEvent = event as? KSMServerConnectionEvent {
serverConnectionEvent(serverConnectionEvent: onServerConnection)
}
}
}

The serverConnectionEvent method processes server connection statuses by checking the event status, performing specific actions (e.g., printing messages or updating status text), and creating a ServerConnectionStatus object with a description, title, and status. It then notifies the delegate about the status change, ensuring the application updates its UI and provides appropriate feedback to the user.

func serverConnectionEvent(serverConnectionEvent: KSMServerConnectionEvent) {
var statusText = ""
switch serverConnectionEvent.connectionStatus {
case .KSMUndefined:
print("KSMUndefined")
case .KSMConnected:
print("KSMConnected")
case .KSMDisconnected:
statusText = "serverModel.state.disconnected".localized(table: localizedTable)
print("KSMDisconnected")
...


Android/Kotlin

Since the connection status of the application is received from the MC SDK, the class should be extended with the EventListener interface.

class ServerModel : EventListener {
...
override fun onEventReceived(event: EventFrameworkEvent?) {
SysUtil.logDebug(tag, "received event : ${event.toString()}")
when (event) {
is ServerConnectionEvent -> {
handleServerConnectionEvent(event)
}
}
}
}
    private fun handleServerConnectionEvent(serverConnectionEvent: ServerConnectionEvent) {
when (serverConnectionEvent.connectionState) {

ConnectionState.UNDEFINED -> {
println("UNDEFINED")
}

ConnectionState.CONNECTED -> {
println("CONNECTED")
}

ConnectionState.DISCONNECTED -> {
println("DISCONNECTED")
}
...
}
}