Reputation: 52
Is it currently possible to coroutines in Kotlin for networking?
I could find examples with threads but not with coroutines.
Upvotes: 1
Views: 2148
Reputation: 3890
You may use Dispatchers.IO
dispatcher to work with sockets from coroutines like you do it from threads - sockets are blocking I/O, so each sockets takes a whole thread, and this dispatcher can launch a LOT of threads.
Also there are some non-blocking I/O libraries for Java, and you may find adapters from them to Kotlin Coroutines API (for example, you may use this proxy between Netty and Coroutines).
Upvotes: 2