We have built software that consists of two parts, a GUI (front-end) running in the browser and a kernel (back-end) with Go compiled into exe.
To glue these two pieces together, we used nodejs+expressjs+socket.io running on the local machine. Nodejs talks to the browser over http/socket.io, and it also "spawn" Go exe as child_process.
Now with websocketd, we can skip the nodejs+expressjs+socket.io part. That is great.
The difficulty is: the GUI in the browser used to send JSON to nodejs, which is then written into a configuration file. Our kernel exe will read that JSON configuration file to determine what to do.
I guess one cannot send JSON over STDIN/STDOUT. I can certainly do command line "flag" for Go to parse.
Question: Is there a better way doing this?
You could run a websocket server in your go app, where you could handle all the related routing and logic. It would probably make things a lot simpler, and more flexible.
Here is a library I have used previously, and can recommend: https://github.com/gorilla/websocket
This is very late to the party and probably won't help at this point, but it might help future people who see this.
Websocketd supports a binary transfer type and removes the /n
line endings. This might be used by just buffering in and outbound binary streams and just reading them as json on either end.
https://github.com/joewalnes/websocketd/issues/38
websocketd --devconsole --port 8080 --binary --devconsole stdbuf -i0 -io0 cat
The --binary
flag being the important part of that link. (Copied in the even the link ever dies).