gows

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 20, 2021 License: MIT Imports: 7 Imported by: 0

README

GOWS

GOWS is GoLang web-socket module Provides you with ease of handling web socket connections with a few lines, it supports multi-connection on one channel, Ping/Pong handler, saves multi concurrency writes on hub and connections.


Installation :

go get -u github.com/es-code/gows

Usage :


var ws *gows.Hub

func main()  {
ws = gows.Init()

//endpoint to open ws connection and read messages , write message to connection
http.HandleFunc("/message/listen",messageSocket)
//start web server
http.ListenAndServe(":9000",nil)

}
func messageSocket(res http.ResponseWriter, req *http.Request)  {

channel:=req.FormValue("channel")

//open connection for current request
conn,err:=ws.Open(channel,res,req)

if err!=nil{
fmt.Println("ws error open conn")
}
//start listen for messages
err=ws.Listen(conn,func(messageType int, message []byte) {
//your code here to handle every message
//example : re-write message on channel
ws.WriteOnChannel(channel,message)
})

if err!=nil{
fmt.Println("gows connection ended")
}
return

}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Uuid

func Uuid() string

Types

type Connection

type Connection struct {
	Channel string
	ConnId  string
	// contains filtered or unexported fields
}

type Hub

type Hub struct {
	Upgrader       *websocket.Upgrader
	WriteWait      time.Duration
	PongWait       time.Duration
	PingPeriod     time.Duration
	MaxMessageSize int64
	// contains filtered or unexported fields
}

func Init

func Init() *Hub

func (*Hub) Listen

func (h *Hub) Listen(c *Connection, messageHandler func(messageType int, message []byte)) error

func (*Hub) Open

func (h *Hub) Open(channel string, res http.ResponseWriter, req *http.Request) (*Connection, error)

func (*Hub) RemoveConn

func (h *Hub) RemoveConn(c *Connection)

func (*Hub) SetDefault

func (h *Hub) SetDefault()

func (*Hub) WriteOnChannel

func (h *Hub) WriteOnChannel(channel string, message []byte)

func (*Hub) WriteOnConn

func (h *Hub) WriteOnConn(c *Connection, messageType int, message []byte) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL