commit 14/10/2025
Soundbank Menu beres
This commit is contained in:
@@ -20,7 +20,6 @@ class BarixConnection(val index: UInt, var channel: String, val ipaddress: Strin
|
||||
private var _sd: Int = 0
|
||||
private var _vu: Int = 0
|
||||
private var _onlinecounter = 0
|
||||
private val udp = DatagramSocket(0)
|
||||
private val inet = InetSocketAddress(ipaddress, port)
|
||||
private val maxUDPsize = 1000
|
||||
private var _tcp: Socket? = null
|
||||
@@ -105,26 +104,26 @@ class BarixConnection(val index: UInt, var channel: String, val ipaddress: Strin
|
||||
fun SendData(data: ByteArray, cbOK: Consumer<String>, cbFail: Consumer<String>) {
|
||||
if (data.isNotEmpty()) {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
|
||||
val bb = ByteBuffer.wrap(data)
|
||||
while(bb.hasRemaining()){
|
||||
try {
|
||||
val chunk = ByteArray(if (bb.remaining() > maxUDPsize) maxUDPsize else bb.remaining())
|
||||
bb.get(chunk)
|
||||
//println("Buffer remain: $bufferRemain, sending chunk size: ${chunk.size}")
|
||||
while(bufferRemain<chunk.size){
|
||||
delay(10)
|
||||
//println("Waiting until buffer enough..")
|
||||
DatagramSocket().use{ udp ->
|
||||
val bb = ByteBuffer.wrap(data)
|
||||
while(bb.hasRemaining()){
|
||||
try {
|
||||
val chunk = ByteArray(if (bb.remaining() > maxUDPsize) maxUDPsize else bb.remaining())
|
||||
bb.get(chunk)
|
||||
//println("Buffer remain: $bufferRemain, sending chunk size: ${chunk.size}")
|
||||
while(bufferRemain<chunk.size){
|
||||
delay(10)
|
||||
//println("Waiting until buffer enough..")
|
||||
}
|
||||
udp.send(DatagramPacket(chunk, chunk.size, inet))
|
||||
delay(2)
|
||||
} catch (e: Exception) {
|
||||
cbFail.accept("SendData to $ipaddress:$port failed, message: ${e.message}")
|
||||
return@launch
|
||||
}
|
||||
udp.send(DatagramPacket(chunk, chunk.size, inet))
|
||||
delay(2)
|
||||
} catch (e: Exception) {
|
||||
cbFail.accept("SendData to $ipaddress:$port failed, message: ${e.message}")
|
||||
return@launch
|
||||
}
|
||||
cbOK.accept("SendData to $channel ($ipaddress:$port) succeeded, ${data.size} bytes sent")
|
||||
}
|
||||
cbOK.accept("SendData to $channel ($ipaddress:$port) succeeded, ${data.size} bytes sent")
|
||||
|
||||
}
|
||||
|
||||
} else cbFail.accept("SendData to $ipaddress:$port failed, data is empty")
|
||||
|
||||
Reference in New Issue
Block a user