Hello again,
So i'm trying to make a simple command forwarder to connect my home computer to a server I own, so that I can push commands to my server and my home pc gets it. Those commands are simple pause/resume for my downloader. My design is, that on a server, I run a hub instance, which creates a websocket server for backend (I call it backend window) and another websocket server for future browser requests. I'm trying to make it work by setting a hub first (which listens for a backend connection and client connections). I'm bounding those two instances with a channel, they run concurrently on ListenAndServe(). When a client connects and sends a message to the hub, it gets streamed through a channel to backend window and then to the real backend (on my home pc). When backend responds to the backend window on the hub, the hub prints the result for the client.
The best I could come up with is that the first message from a client gets passed and parsed in Interpret() method (on the backend - my home pc) and it actually works as intended. Later commands though get an EOF error in the backend instance (again, home pc) and they loop forever. I've tried closing the connection or responding with empty strings to the hub, but I don't really know how to handle an EOF on a websocket (there are only Read() and Write() methods).
The fact that only the first message gets through I've achieved by setting 0 as a http timeout for both read and write on backend window and hub interface.
To compile the source code, put the git repo in GOPATH, then just do `go build gosab/cmd`, run it by issuing:
./cmd -mode="hub" -backend=":8082" -hub=":8083"
./cmd -mode="backend" -hub="localhost:8082/" # hub option here gives the address to backend window
To test it from a browser, execute this javascript in your webkit inspector/firebug:
var s = new WebSocket("ws://localhost:8083")
s.send("1 5")
This is the output from the hub command (first) that I'm aiming for:
got 1 5
sending 1 5 to backend
Backend says: Sabnzbd paused for 5 minutes
When "Backend says: x" matches anything from backend/interpreter, it means that it works.
Thank you for your time.