Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
65 lines (49 sloc) 1.91 KB
package main
import (
func main() {
var (
udpHost string
wsHost string
zmqAddress string
sseHost string
globalAccessToken string
// WS and UDP hosts can be different, ex. UDP could be listening on a private IP while WS is public
flag.StringVar(&zmqAddress, "zmqsocket", "tcp://", "ZMQ socket address to send events to")
flag.StringVar(&wsHost, "wshost", "localhost:5555", "Websocket host:port")
flag.StringVar(&udpHost, "udphost", "localhost:5555", "host:port to bind for UDP datagrams")
flag.StringVar(&sseHost, "ssehost", "localhost:5556", "host:port to bind for Server Sent Events")
flag.StringVar(&globalAccessToken, "accesstoken", "", "Access token required to connect to SSE events")
// Start up UDP daemon +++++++++++++++++++++++++++++++++++++++++++++++
daemon, err := udp.NewDaemon(udpHost)
if err != nil {
// Setup Websockets hub ++++++++++++++++++++++++++++++++++++++++++++++
wshub := ws.HandleWebsocketsHub("/ws")
log.Println("websocket server at " + wsHost + "/ws")
// Push incoming UDP messages to multiple listeners ++++++++++++++++++
// Push all events
// Start up PUB ZMQ client
zmqObserver := fanout.NewZmq(zmqAddress)
// Push incoming UDP events down ZMQ pub/sub socket
// Firehose subscriber
firehoseDaemon := firehose.NewServer()
log.Println("ZMQ fanout at", zmqAddress)
authenticatedFirehose := firehose.NewAuthHandler(firehoseDaemon, globalAccessToken)
go http.ListenAndServe(sseHost, authenticatedFirehose)
log.Println("Server Sent Events at", sseHost)
log.Fatal("HTTP server error: ", http.ListenAndServe(wsHost, nil))