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?
Great to know there's an alternative. I'll probably stick with the single execution anyway, but great to see this tcpserver
approach 🙂
Do you mean at a time, or that you want it to repeatedly listen, accept, then (upon close) go back to listening?
At a time, like, I can't have more than one connection to the socket repl at the same time
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.)
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.(I'd like to see <http://github.com/chzyer/readline|github.com/chzyer/readline>
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.)
Forgot to mention: each client does telnet localhost 8888
in my setup.