Example of ktor implementation for sse (server-sent events) in KMM project. With demo server that emits sse events.
-
Find
local.properties
file in project root folder. If not present add it. -
Add your ip address to
local.properties
. Something like this (wherexxx.xxx.x.xxx
is your ip address):
## This file is automatically generated by Android Studio.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file should *NOT* be checked into Version Control Systems,
# as it contains information specific to your local configuration.
#
# Location of the SDK. This is only used by Gradle.
# For customization when using a Version Control System, please read the
# header note.
sdk.dir=BLABLABALA # generated by Android studio
ip.address=xxx.xxx.x.xxx # <--------------------------- ADD THIS !!!!
-
Build project
-
Run backend application (:backend -> Server.kt)
-
Run Android or iOS app
-
backend
-> contains demo server that emits sse events (ktor server) -
shared
-> contains ktor client implementation for sse event & common code for iOS/Android apps -
shared-models
-> contains constants and models that are shared between backend and mobile apps (e.g.SseEvent
model) -
androidApp -> Android app code
-
iosApp -> iOS app code