Skip to content

joaosoft/socket

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

socket

Build Status | codecov | Go Report Card | GoDoc

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.

How it works ?

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

Usage

This examples are available in the project at socket/examples

Server

func main() {
	// server
	server, err := socket.NewServer()
	if err != nil {
		panic(err)
	}

	if err := server.Start(); err != nil {
		panic(err)
	}
}

Client

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()
}

Dependecy Management

Dependency

Project dependencies are managed using Dep. Read more about Dep.

  • Get dependency manager: go get github.com/joaosoft/dependency
  • Install dependencies: dependency get

Go

go get github.com/joaosoft/socket

Known issues

Follow me at

Facebook: https://www.facebook.com/joaosoft

LinkedIn: https://www.linkedin.com/in/jo%C3%A3o-ribeiro-b2775438/

If you have something to add, please let me know joaosoft@gmail.com

About

A service that allows you to broadcast Publish and Listen messages to/from the server.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors