Hey everybody! I'm currently investigating the pos...
# ktor
e
Hey everybody! I'm currently investigating the possibility of writing a single multiplatform codebase to interact with an API via TCP socket. Platforms are the JVM and NodeJS. What's the current status for Ktor, is it viable for NodeJS? I know for sure there are no issues on the JVM.
r
I’ve had good experiences using it with node.js
I’ve built a few “sdks” that are tested via node.js tests and then used by a react app in a browser, so its pretty solid
i’m speaking of KTOR client specifically of course, not the server, which AFAIK doesn’t run on node.js last i checked
e
Thanks! Yes it doesn't run as a server, I think there is pending ticket to split up the codebase between browser and Node. What about typings for Node stuff, like for example the Net module (for Socket)? The library will be consumed by a VS Code extension
r
For the multiplatform side, you should be able to write your module using pure KTOR kotlin, and it should automatically pick up the node.js adapters for you. Though maybe I’m not quite imagining what you have in mind.
e
it should automatically pick up the node.js adapters for you
Interesting! I don't particularly like the automagic part, but maybe I can learn how it works somewhere, is Ktor aware that I'm running under Node and not in the browser? The client implementation is pretty straightforward. Bytes coming from the socket connection should be de-serialized from XML to objects then usable from TypeScript (VS Code side)
I'm looking at the
Socket
documentation, and it says
jvmAndNix
Am I looking at the wrong page?
r
ahh so you’re looking for pure network comms, not just http or websocket requests, yeah?
e
Oh yeah! Pure TCP socket
r
yeah i glossed over that slightly in your initial message. I can confidently recommend Ktor Client for JS websocket and HTTP communication. Can’t confirm or deny for pure TCP
✔️ 1
e
Thanks anyway! I can't find many resources on Google. Only about HTTP calls or WS
Wondering if Ktor interfaces can be re-used to provide our own implementation of the Socket
r
out of curiosity, what are you planning to communicate with via the socket? Network hardware?
e
@Rob Murdock z/OS, mainframe
👍 1
Oh wait, last time I checked the NodeJS typings (kotlinx-nodejs) it was "experimental", have the types been moved to somewhere else now?
r
e
Yup they're there! Wondering then why https://github.com/Kotlin/kotlinx-nodejs doesn't mention it and is still up
h
zOS with JS? Interesting, what do you do exactly? I prefer J9 with the IBM zOS library
e
I can't really go into details but it's a zOS product's IDE integration. zOS is already usable through JS, see https://github.com/zowe
h
Yeah, of course I do know Zowe and it’s VS Code integration based on JS, but I like IntelliJ more.
e
I'd like to pick a multiplatform solution to target multiple integrations, that's the end goal. I don't really want to rewrite the code multiple times. Kotlin seems a good solution but there are small details that I don't like.
h
„Only“ integration or grammar/language support too?
Yes, this is exactly Kotlins strength.
e
Not sure what we'll end up doing. It all depends on how fast/good this core library development goes.
Another alternative would be writing a small local service (e.g., on the JVM), spawn it as a child process and use IPC/RPC on loopback. You can reuse it everywhere.
h
But how is this different to typescript? You also have packages there, don't you?
Sure, there are often alternatives, but they are often workarounds 😄