Skip to content

Commit

Permalink
Ktor 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
niusounds committed Jun 3, 2022
1 parent a8232b0 commit ca52759
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package com.niusounds.libreastream.receiver

import io.ktor.network.selector.ActorSelectorManager
import io.ktor.network.sockets.InetSocketAddress
import io.ktor.network.sockets.aSocket
import io.ktor.utils.io.core.readByteBuffer
import java.net.InetSocketAddress
import java.nio.ByteBuffer
import java.nio.ByteOrder
import kotlin.coroutines.CoroutineContext
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.consumeAsFlow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onCompletion
import java.nio.ByteBuffer
import java.nio.ByteOrder
import kotlin.coroutines.CoroutineContext

/**
* Receive UDP data with Ktor.
Expand All @@ -23,7 +23,7 @@ class KtorUdpReceiver(
override fun receive(): Flow<ByteBuffer> {
val server = aSocket(ActorSelectorManager(ioContext))
.udp()
.bind(InetSocketAddress(port))
.bind(InetSocketAddress("", port))

return server.incoming.consumeAsFlow()
.map {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import com.niusounds.libreastream.ReaStream
import io.ktor.network.selector.ActorSelectorManager
import io.ktor.network.sockets.ConnectedDatagramSocket
import io.ktor.network.sockets.Datagram
import io.ktor.network.sockets.InetSocketAddress
import io.ktor.network.sockets.aSocket
import io.ktor.util.network.NetworkAddress
import io.ktor.utils.io.core.ByteReadPacket
import java.nio.ByteBuffer
import kotlin.coroutines.CoroutineContext
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import java.nio.ByteBuffer
import kotlin.coroutines.CoroutineContext

/**
* Receive UDP data with Ktor.
Expand All @@ -23,7 +23,7 @@ class KtorUdpSender(
private val client: ConnectedDatagramSocket by lazy {
aSocket(ActorSelectorManager(ioContext))
.udp()
.connect(NetworkAddress(host, port))
.connect(InetSocketAddress(host, port))
}

override suspend fun send(data: ByteBuffer) = withContext(ioContext) {
Expand Down

0 comments on commit ca52759

Please sign in to comment.