// Echo service func echo(socket *zmq.Socket) (err error) { msg, err := socket.RecvMessage(0) if err != nil { return } _, err = socket.SendMessage(msg) return }
func ProcessEvents(self string, statebe, statefe *zmq.Socket) { poller := zmq.NewPoller() poller.Add(statefe, zmq.POLLIN) for { // Poll for activity, or 1 second timeout sockets, err := poller.Poll(time.Second) if err != nil { break } // Handle incoming status messages if len(sockets) == 1 { msg, _ := statefe.RecvMessage(0) peerName := msg[0] available := msg[1] fmt.Printf("%s - %s workers free\n", peerName, available) } else { statebe.SendMessage(self, rand.Intn(10)) } } }
// Send key-value message to socket; any empty frames are sent as such. func (kvmsg *Kvmsg) Send(socket *zmq.Socket) (err error) { //fmt.Printf("Send to %s: %q\n", socket, kvmsg.frame) kvmsg.encode_props() _, err = socket.SendMessage(kvmsg.frame) return }
func (server *server_t) ping(socket *zmq.Socket) { if time.Now().After(server.ping_at) { socket.SendMessage(server.endpoint, "PING") server.ping_at = time.Now().Add(PING_INTERVAL) } }