commit 14/10/2025
combine with coding steph
This commit is contained in:
@@ -37,31 +37,37 @@ class TCP_Barix_Command_Server {
|
||||
val key : String = socket.inetAddress.hostAddress
|
||||
socketMap[key] = socket
|
||||
Logger.info { "Start communicating with Streamer Output with IP : $key" }
|
||||
val din = socket.getInputStream()
|
||||
while (isActive) {
|
||||
if (din.available()>0){
|
||||
val bb = ByteArray(din.available())
|
||||
din.read(bb)
|
||||
// B4A format, 4 bytes di depan adalah size
|
||||
val str = String(bb, 4, bb.size - 4)
|
||||
if (ValidString(str)) {
|
||||
// Valid command from Barix is in format $"STATUSBARIX;VU;BuffRemain;StatusData"$
|
||||
pattern.find(str)?.let { matchResult ->
|
||||
val (vu, buffremain, statusdata) = matchResult.destructured
|
||||
val status = BarixStatus(
|
||||
socket.inetAddress.hostAddress,
|
||||
vu.toInt(),
|
||||
buffremain.toInt(),
|
||||
statusdata.toIntOrNull() ?: 0
|
||||
)
|
||||
//Logger.info { "Received valid command from $key : $status" }
|
||||
cb.accept(status)
|
||||
} ?: run {
|
||||
Logger.warn { "Invalid command format from $key : $str" }
|
||||
try{
|
||||
val din = socket.getInputStream()
|
||||
while (isActive) {
|
||||
|
||||
if (din.available()>0){
|
||||
val bb = ByteArray(din.available())
|
||||
din.read(bb)
|
||||
// B4A format, 4 bytes di depan adalah size
|
||||
val str = String(bb, 4, bb.size - 4)
|
||||
if (ValidString(str)) {
|
||||
// Valid command from Barix is in format $"STATUSBARIX;VU;BuffRemain;StatusData"$
|
||||
pattern.find(str)?.let { matchResult ->
|
||||
val (vu, buffremain, statusdata) = matchResult.destructured
|
||||
val status = BarixStatus(
|
||||
socket.inetAddress.hostAddress,
|
||||
vu.toInt(),
|
||||
buffremain.toInt(),
|
||||
statusdata.toIntOrNull() ?: 0
|
||||
)
|
||||
//Logger.info { "Received valid command from $key : $status" }
|
||||
cb.accept(status)
|
||||
} ?: run {
|
||||
Logger.warn { "Invalid command format from $key : $str" }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (ex:Exception){
|
||||
Logger.error { "Error in communication with Streamer Output with IP $key, Message : ${ex.message}" }
|
||||
}
|
||||
|
||||
Logger.info { "Finished communicating with Streamer Output with IP $key" }
|
||||
socketMap.remove(key)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user