How can I hack kakoune to use a custom server?

While server -> client communication is well documented, and easy to pick with kak -ui json and thanks to the great wiki article by @Delapouite .
But I wonder how can I make kakoune listen to my own server, and send “draw” as input to a kakoune client.

An example if the above is mot clear enought:
Creating a python script that open a socket “mypyserver” that send json RPC . Stuff like:

{ "jsonrpc": "2.0", "method": "draw", "params": [[[...{ "face": { ...}, "contents": "Hello from python" },...] }

Then I could connect to this server by running

kak -c 'mypyserver'

And I would see a kakoune buffer with "“Hello from python”

The JSON-RPC interface is not actually the communication between the Kakoune client and server. When you run kak -ui json, that is a Kakoune client, talking to a server somewhere else. The actual client-server protocol is not documented anywhere, but is implemented in src/remote.cc. If you take a look, the protocol actually resembles the JSON-RPC interface, but it’s using a custom binary protocol. If you look in that file for the connect_to function, and the things it calls, and the things that call it, you should get a good idea how the protocol works.

But, basically, yes - if you listen on the right socket, and send and interpret the right protocol, Kakoune clients should be able to connect and you can make them display whatever.

2 Likes

Kuddos for the code is pretty easy to read !

I tried to listen to the socket file in my XDG_RUNTIME_DIR with
nc -U /run/user/1000/kakoune/1234
who didn’t show anything and
socat -d -d -d -d - UNIX-CONNECT:/run/user/1000/kakoune/1234 who was very cryptic.

I don’t think I have the right method to listen to RPC communication. I’ll have to dig into it a bit more. but thanks for the pointer.

Some demo code available through Delapouite / kakoune-electron

“The communication is established through the JSON-RPC api.”

That’s for the client implementation. I’m asking about the server

Thanks for calling my out on that buddy!! I was laughing for a while on that one yesterday. Today I thought of my smart-ass come back…get ready to smile.

Oh your looking for The answer, sorry we only do pieces to the puzzle on plant earth” :rofl:

flame war :clap: flame war :clap: flame war :clap:

When pencil hits paper for the server solution/problem can you post your findings or link your repo, I’m interested in the outcome. Thanks bye :wave: