I was working on a StackOverflow helper program (that sends me notifications) when I noticed something rather interesting in StackOverflow's Network tab:
StackOverflow uses WebSockets (not too surprising, but good to know)! For this challenge, we will be conquering StackOverflow's web socket server.
This particular method could be transferred over to other domains related to StackExchange, but StackOverflow is very popular and a good example. Feel free to lookup tags for other domains on StackExchange (feel free to connect to those instead, although I doubt it would reduce byte count since StackOverflow has id 1).
StackOverflow's Unofficial WebSocket API
There are two separate WebSocket servers you could use:
- The secure,
- Or the insecure,
Since we are code golfing and we aren't going to be sending any not-already-public-information, I suspect people will lean more toward the insecure option.
Next, in order to subscribe to our favorite tag, we need to send the following to the WebSocket to 'subscribe' to the tag's feed.
You can replace
The server will occasional send heartbeat requests. You must reply with
hb (so you can keep the connection alive).
A heartbeat requests looks as follows:
Input: Any tag the user wants to receive updates about.
Output: Should be the first question (from when you connected to the WebSocket) and all consecutive available for said tag on StackOverflow.
- You must use WebSockets. Or, at least connect to
ws://qa.sockets.stackexchange.com) and use it to receive updates for the inputted tag. If you can find a better way of doing it (like not using the
1-questions-newest-tag-<tag>but still receive updates fo the inputted tag) by all means. Or if you can write your own WebSocket equivalent in less bytes, even cooler.
- Least number of bytes wins!
External libraries are encouraged. Many programming languages have a compatible library.