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:

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")
}
...
}
}

In general, there are 9 different types of connection states on both platforms, and these status are known as UNDEFINED CONNECTED DISCONNECTED CONNECTION_LOST RECONNECTED REACHABLE NOT_REACHABLE INVALID_STATE RESTART_ON_NOT_REACHABLE