8000 GitHub - lhy940808/comet: A light-weight Golang WebSocket server
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

lhy940808/comet

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A light-weight Golang WebSocket Comet Server

You can use Comet for realtime peer-to-peer message push or broadcasting.

The Comet API provide two different protocols for receiver and sender. Message receiver using websocket protocol, as well as Messsage sender using HTTP protocol.


The design is very simple and light-weighted. When a web browser client connected, the Comet server launch a goroutine simultaneously and monitor it. Monitor corresponding to the client send a heartbeat message per 5 second in order to check the connection. Once the connection break, the Comet will remove this client. So, in this way, the frontend will never pay attention to the Comet server and never should send heartbeat to server. Control is in server side completely.

1) Run

$ go get github.com/olzhy/comet
$ go run main.go

2) API for web Browser

You can use JavaScript WebSocket API to establish a connection to Comet server. The address is:

ws://localhost:8080/comet?user_id=:user_id

Please give a arbitrary valid :user_id param, such as x.

3) Send message

You can send a message to the browser user client in step 2. Method is post, body is 'aplication/json' format. user_id and message param required. such as:

curl -d '{"user_id": "x", "message": "test"}' http://localhost:8080/messages

Then the user x you specified will receive the test message.

For more details, please visit my blog.

4) Test page

You can test WebSocket connection and message receive in this page.

http://localhost:8080/index/

About

A light-weight Golang WebSocket server

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 70.7%
  • JavaScript 20.5%
  • HTML 8.8%
0