Howto: Websockets in Mudlet

Post Reply
perlsaiyan
Posts: 2
Joined: Thu Apr 21, 2022 4:58 pm

Howto: Websockets in Mudlet

Post by perlsaiyan »

I'm working on a web-based visualization system for MUDding, with command and control from a web interface. The system runs with WebSockets, authenticated via an "Authorization" header and an API-KEY. I did some basic work to get this functional in Mudlet using the Websocat utility, listed on GitHub for many OS types and source code (direct links not allowed).
Code: [show] | [select all] lua
ws = spawn(function() end, "websocat",
"wss://url",
"-H",
"Authorization: API-KEY <<secret key>>")
After this, can use ws.send() to send information from your session to the websocat, and the function can be replaced to parse information coming back. A sample screenshot from a browser is attached, the text field will submit commands back to the mud client. I pass simple key/value pairs to populate the web components in real-time.

Hope this helps someone.
Attachments
Selection_376.jpg

neve
Posts: 3
Joined: Thu Apr 21, 2022 6:17 pm

Re: Howto: Websockets in Mudlet

Post by neve »

Whoa that's extremely cool! I was considering this option for a parser but ran into trouble with spawn and send.
and the function can be replaced to parse information coming back.
Could you give an example of that? I never could get send() to work. And I could only get a response from spawn() if the receiving command did an exit 0, so it had to be pretty much stateless. Actually now that I think about it maybe send was working outbound, but just wasn't receiving data back?

Anyway I mostly abandoned it in favor of a REST api using the http functions, which pretty much work as expected. I'm still interested in this approach though.

perlsaiyan
Posts: 2
Joined: Thu Apr 21, 2022 4:58 pm

Re: Howto: Websockets in Mudlet

Post by perlsaiyan »

Thanks. I'm not a mudlet guy, I use the *cough* other thing as my primary client. if you define a function websocketParser(), and use that instead of function() end, it will be run with an argument on every received message. If you want to play around with my central socket bit, I'm on the discord as perlsaiyan#5952 . A lot of the website functions are specific to Legends of Kallisti, but the monitor system is mud agnostic.

The trick for me with ws.send() was to include \n in the string I sent.

neve
Posts: 3
Joined: Thu Apr 21, 2022 6:17 pm

Re: Howto: Websockets in Mudlet

Post by neve »

Ahhh maybe I did miss that. I noticed it about spawn but that might have been later. That little feature is so strange and frankly a little alarming, I'm not even sure how I feel about depending on it. Plus I might like to distribute this code later and shelling out like that is a whole extra set of stuff to consider.

Otoh having the entire world of compilers and languages available is kinda sick. Having for example a custom tree sitter parser for a mud would be so powerful.

Post Reply