korlibs / korlibs/korlibs-io

AsyncClient example how to read data on iOS

Open
#5 0 comments 0 reactions 1 assignee Claimed by @soywiz View on GitHub
bug
Dominant language
Kotlin
Stars
2
Forks
2
PR merge metrics
No merged PRs in 30d

Description

It is not clear (or may be a bug in library) how to send and read from tcp sockets on iOS:

Here is example code that works on jvm, but I can't make it work on ios. In both cases message is sent to server. in JVM it also receive message. But on ios it never able to read message from socket.

Common:
```
suspend fun connectToServer() {

val a1 = async(mainDispatcher) {

tcpClient = createTcpClient(SKES_LOCAL_URL, SKES_PORT_BASE+SK_PORTS_CONTROL, false)
println("tcpClient...")

val a2 = async(mainDispatcher) {
println("tcpClient() read")
while (true) {
println("tcpClient() wait for read")
//val data = tcpClient.readAvailable()
val buffer = ByteArray(100)
val bytesRead = tcpClient.read(buffer, 0, 20) //never returned on iOS
println("data: ${buffer.asList()}")
}
}

println("before send")
val initData = byteArrayOf(1,2,3,4,5)
tcpClient.write(initData)
println("sent")
}

println("done")

while (true) {
Thread_sleep(100)
}
}
```

ios:
```
fun connectToServer() {
runBlocking {
connectToServer()
}
}
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.