fixed local host with accept and added tests
This commit is contained in:
1 parent
f02b390ed4
commit
c6ac6f5907
10 files changed
+86
-11
No files matched your search
@@ -18,7 +18,7 @@ actual fun acceptTcpDevice(port: Int): Flow<InetTransportDevice> {
|
||||
return flow {
|
||||
val socket = withContext(Dispatchers.IO) {
|
||||
AsynchronousServerSocketChannel.open().also {
|
||||
it.bind(InetSocketAddress(InetAddress.getLocalHost(), port))
|
||||
it.bind(InetSocketAddress(port))
|
||||
}
|
||||
}
|
||||
while (true) {
|
||||
@@ -33,6 +33,8 @@ actual fun acceptTcpDevice(port: Int): Flow<InetTransportDevice> {
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun connectTcpDevice(address: String) = connectTcpDevice(address.toNetworkAddress())
|
||||
suspend fun connectTcpDevice(host: String, port: Int) = connectTcpDevice(NetworkAddress(host,port))
|
||||
actual suspend fun connectTcpDevice(address: NetworkAddress): InetTransportDevice {
|
||||
address as JvmNetworkAddress
|
||||
val socket = withContext(Dispatchers.IO) {
|
||||
|
||||
@@ -13,7 +13,7 @@ import java.util.concurrent.atomic.AtomicInteger
|
||||
private val counter = AtomicInteger(0)
|
||||
|
||||
class JvmNetworkAddress(val inetAddress: InetAddress, override val port: Int) : NetworkAddress {
|
||||
override val host: String by lazy { inetAddress.hostName }
|
||||
override val host: String by lazy { inetAddress.canonicalHostName }
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (other !is JvmNetworkAddress) return false
|
||||
@@ -32,6 +32,7 @@ class JvmNetworkAddress(val inetAddress: InetAddress, override val port: Int) :
|
||||
return result
|
||||
}
|
||||
|
||||
override fun toString(): String = "$host:$port"
|
||||
}
|
||||
|
||||
class UdpDatagram(override val message: UByteArray, val inetAddress: InetAddress, val port: Int) : Datagram {
|
||||
|
||||
Reference in new issue
Block a user