Contaso
Contaso

Reputation: 52

What is the standard way to use Kotlin+Sockets+Coroutines?

Is it currently possible to coroutines in Kotlin for networking?

I could find examples with threads but not with coroutines.

Upvotes: 1

Views: 2148

Answers (1)

ardenit
ardenit

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

Related Questions