Hey, If someone can help me to setup a project in ...
# kotlin-native
s
Hey, If someone can help me to setup a project in Kotlin/Native targeting windowsOS, linuxOS and macOS. In this project I want to create a TCP socket and client to transmit the data. Thanks in advance.
1
s
Feel free to use https://github.com/saldoukhov/chuck as a template
s
Hi @Sergey Aldoukhov thanks for the quick response, I was able to create a sample project setup for the kotlin/native. Next want to create an application for the tcp server socket to accept the data from the local lan targeting OS windows,linux and mac. It should be without support of the JVM. I have explore many blogs and git repos but did not find the self explanatory blog or right information.
h
Use ktor-network
s
Hi @hfhbd, by any chance can you suggest any git link for the reference. Or reference code is available.
h
https://github.com/ktorio/ktor/tree/main/ktor-network It’s the networking module of ktor and used by Ktor CIO, mostly http. The documentation of ktor focus on the clients, so networking tests are the sample code.
e
But ktor doesn't have TCP support for Windows unfortunately
s
Hi @hfhbd thanks for links. But not able to load and run.
Hi @Edoardo Luppi yes, so I'm trying to use the native for the but getting limited resources. I am new to kotlin.
Copy code
memScoped {
    val serverAddress = alloc<sockaddr_in>()
    serverAddress.sin_family = AF_INET.toShort()
    serverAddress.sin_port = htons(15583)
    serverAddress.sin_addr.s_addr = inet_addr("0.0.0.0")
for this code getting an error :Unresolved reference: s_addr Import the below reference
Copy code
import kotlinx.cinterop.*
import platform.posix.*
import platform.windows.htonl
import kotlin.native.concurrent.*
One thin I was found that if write code like
Copy code
serverAddress.sin_addr.S_un.S_addr = inet_addr("0.0.0.0")
then no issue was found but it fails at bind method
Copy code
if (bind(serverSocket, serverAddress.ptr.reinterpret(), sizeOf<sockaddr_in>().convert()) < 0) {
    perror("server: can't bind local address")
    return
}
Return the error. can't bind local address.