I have a UDP raw socket that I want to transmit da...
# ktor
l
I have a UDP raw socket that I want to transmit data through very rapidly (every x ms). I was wondering if there is any difference between using the
SendChannel
provided or whether I should be using
openWriteChannel
and sending my data through the returned
ByteWriteChannel
instead.
a
I think it's better to use the
SendChannel
because it's already available. Here is an example:
Copy code
val address = NetworkAddress("127.0.0.1", 12345)
val socketBuilder: UDPSocketBuilder = aSocket(ActorSelectorManager(<http://Dispatchers.IO|Dispatchers.IO>)).udp()
val socket = socketBuilder.connect(address)

val packet = BytePacketBuilder().apply {
    writeFully("test".toByteArray())
}.build()

socket.outgoing.send(Datagram(address = address, packet = packet))