websocket 增加多分组 fork https://github.com/olahol/melody
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Ola Holmström dce8735ee4 update readme 10 years ago
examples fix demo use gif instead of webm 10 years ago
.travis.yml fix travis 10 years ago
README.md update readme 10 years ago
config.go documentation 10 years ago
envelope.go first version 10 years ago
hub.go documentation 10 years ago
melody.go fix documentation 10 years ago
melody_test.go documentation 10 years ago
session.go fix documentation 10 years ago

README.md

melody

GoDoc Build Status

🎶 Simple websocket framework for Go

Melody is websocket framework based on github.com/gorilla/websocket that abstracts away the more tedious parts of handling websockets. Features include:

  • Timeouts for write and read.
  • Built-in ping/pong handling.
  • Message buffer for connections making concurrent writing easy.
  • Simple broadcasting to all or selected sessions.

Install

go get github.com/olahol/melody

Example

Simple broadcasting chat server, error handling left as en exercise for the developer.

Chat demo

package main

import (
	"github.com/olahol/melody"
	"github.com/gin-gonic/gin"
	"net/http"
)

func main() {
	r := gin.Default()
	m := melody.New()

	r.GET("/", func(c *gin.Context) {
		http.ServeFile(c.Writer, c.Request, "index.html")
	})

	r.GET("/ws", func(c *gin.Context) {
		m.HandleRequest(c.Writer, c.Request)
	})

	m.HandleMessage(func(s *melody.Session, msg []byte) {
		m.Broadcast(msg)
	})

	r.Run(":5000")
}

Documentation