Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AsyncClient example how to read data on iOS #589

Open
petrukhnov opened this issue Dec 20, 2019 · 0 comments
Open

AsyncClient example how to read data on iOS #589

petrukhnov opened this issue Dec 20, 2019 · 0 comments
Assignees
Labels

Comments

@petrukhnov
Copy link

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()
    }
}
@soywiz soywiz self-assigned this Dec 20, 2019
@soywiz soywiz added the bug label Feb 1, 2020
@soywiz soywiz transferred this issue from soywiz-archive/korio Jul 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Pending
Development

No branches or pull requests

2 participants