Remove ktor-network dependency use native socket

This commit is contained in:
2025-09-30 10:50:08 +08:00
parent dceb9953af
commit 52f3756be3
21 files changed
+649 -179

No files matched your search

-43
View File
@@ -1,43 +0,0 @@
/*
* Copyright © 2025 RTAkland
* Author: RTAkland
* Date: 9/29/25
*/
package test
import cn.rtast.nmdns.broadcast
import cn.rtast.nmdns.randomMacAddress
import cn.rtast.nmdns.registerService
import cn.rtast.nmdns.sleep1
import kotlinx.coroutines.runBlocking
import kotlin.test.Test
class LinuxTest {
@Test
fun `test on linux`() {
runBlocking {
val service = registerService(
serviceType = "_airplay._tcp.local.",
serviceName = "AP@RTAST",
hostname = "rtakland.local.",
ipAddress = "192.168.10.104",
port = 7001,
bindAddress = "192.168.10.104",
mdnsPort = 5356,
txtRecords = listOf(
"deviceid=${randomMacAddress()}",
"model=AppleTV3,2C",
"features=0x5A7FFFF7,0x1E",
"srcvers=220.68",
"pk=f3769a660475d27b4f6040381d784645e13e21c53e6d2da6a8c3d757086fc336"
)
)
while (true) {
service.broadcast()
sleep1(2)
}
}
}
}
+39
View File
@@ -0,0 +1,39 @@
/*
* Copyright © 2025 RTAkland
* Author: RTAkland
* Date: 9/29/25
*/
package test
import cn.rtast.nmdns.randomMacAddress
import cn.rtast.nmdns.registerService
import cn.rtast.nmdns.sleep1
import kotlin.test.Test
class TestLinux {
@Test
fun `test on linux`() {
val service = registerService(
serviceType = "_airplay._tcp.local.",
serviceName = "AP@RTAST",
hostname = "rtakland.local.",
ipAddress = "192.168.10.104",
port = 7001,
bindAddress = "192.168.10.104",
mdnsPort = 5356,
txtRecords = listOf(
"deviceid=${randomMacAddress()}",
"model=AppleTV3,2C",
"features=0x5A7FFFF7,0x1E",
"srcvers=220.68",
"pk=f3769a660475d27b4f6040381d784645e13e21c53e6d2da6a8c3d757086fc336"
)
)
while (true) {
service.broadcast()
sleep1(2)
}
}
}
+19
View File
@@ -0,0 +1,19 @@
/*
* Copyright © 2025 RTAkland
* Author: RTAkland
* Date: 9/30/25
*/
package test
import cn.rtast.nmdns.randomMacAddress
import kotlin.test.Test
class TestMacAddr {
@Test
fun `test generate mac address`() {
println(randomMacAddress())
}
}
+42
View File
@@ -0,0 +1,42 @@
/*
* Copyright © 2025 RTAkland
* Author: RTAkland
* Date: 9/30/25
*/
package test
import cn.rtast.nmdns.buildPacket
import cn.rtast.nmdns.createSocket
import cn.rtast.nmdns.randomMacAddress
import cn.rtast.nmdns.sleep1
import kotlin.test.Test
class TestNative {
@Test
fun `test native socket`() {
val packet = buildPacket(
serviceType = "_airplay._tcp.local.",
serviceName = "AP@RTAST._airplay._tcp.local.",
hostname = "rtakland.local.",
ip = "192.168.10.104",
port = 7001,
txtRecords = listOf(
"deviceid=${randomMacAddress()}",
"model=AppleTV3,2C",
"features=0x5A7FFFF7,0x1E",
"srcvers=220.68",
"pk=f3769a660475d27b4f6040381d784645e13e21c53e6d2da6a8c3d757086fc336"
)
)
val service = createSocket()
.bind("192.168.10.104", 4546)
while (true) {
service.send(packet.copyOf())
sleep1(2)
}
}
}