A service that allows you to broadcast Publish and Listen messages to/from the server.
If i miss something or you have something interesting, please be part of this project. Let me know! My contact is at the end.
Flow example:
- CLIENT: creates a gateway server
- CLIENT: subscribe a topic/channel on the server
- SERVER: register the client on the topic/channel with the gateway to call it back later
- CLIENT: send a message to a topic/channel
- SERVER: receives the message and broadcast the message to all registered clients
- CLIENT: all clients receive the message sent
- CLIENT: unsubscribe the topic/channel on the server
This examples are available in the project at socket/examples
func main() {
// server
server, err := socket.NewServer()
if err != nil {
panic(err)
}
if err := server.Start(); err != nil {
panic(err)
}
}func main() {
client, err := socket.NewClient()
if err != nil {
panic(err)
}
if err := client.Start(); err != nil {
panic(err)
}
if err := client.Subscribe("topic_1", "channel_1"); err != nil {
panic(err)
}
client.Listen("topic_1", "channel_1", func(message []byte) error {
fmt.Printf("\nreceived on listener the message %s", string(message))
return nil
})
if err := client.Publish("topic_1", "channel_1", []byte("hello, this is a test message")); err != nil {
panic(err)
}
// Unsubscribe
//if err := client.Unsubscribe("topic_1", "channel_1"); err != nil {
// panic(err)
//}
client.Wait()
}Project dependencies are managed using Dep. Read more about Dep.
- Get dependency manager:
go get github.com/joaosoft/dependency - Install dependencies:
dependency get
go get github.com/joaosoft/socket
Facebook: https://www.facebook.com/joaosoft
LinkedIn: https://www.linkedin.com/in/jo%C3%A3o-ribeiro-b2775438/