Fork me on GitHub
#joker
<
2019-10-28
>
mauricio.szabo03:10:17

Hello, I'm just starting with Joker and I saw that the Socket REPL implementation only accepts a single connection. Is there any reason for that?

jcburley04:10:35

Do you mean at a time, or that you want it to repeatedly listen, accept, then (upon close) go back to listening?

mauricio.szabo04:10:21

At a time, like, I can't have more than one connection to the socket repl at the same time

jcburley05:10:49

Ah. Well, Joker is currently designed for only a single thread of (Joker) code execution. So if you're looking for multiple connections into a single instance of Joker (so they can effectively communicate with each other), that's not available. But if you'd be okay with each connection getting its own instance, you could look into putting an appropriate service (like https://cr.yp.to/ucspi-tcp/tcpserver.html, though I'm sure there are more-modern equivalents) up on the port, and have it launch a unique instance of Joker for each incoming connection. (I haven't yet tried that approach, but I might be giving it a go soon, since it fits some of my use cases for Joker.)

jcburley05:10:20

This seems to work adequately (having done sudo apt install ucspi-tcp on my Ubuntu system):

$ tcpserver localhost 8888 ./tools/joker-server.sh --no-readline
That script (`joker-server.sh`) is simply:
#!/bin/sh

exec 2>&1
joker "$@"
It's rudimentary, but if you want each client to get its own Joker instance, it might be enough for you.

jcburley05:10:33

(I'd like to see support network connections, as some other libraries -- including, I assume, GNU's readline -- do. But that package seems to have been orphaned, as it has some longstanding issues and PRs.)

jcburley05:10:21

Forgot to mention: each client does telnet localhost 8888 in my setup.

mauricio.szabo13:10:42

Great to know there's an alternative. I'll probably stick with the single execution anyway, but great to see this tcpserver approach 🙂