gosocket

package module
v0.0.0-...-0fad943 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2022 License: BSD-2-Clause Imports: 11 Imported by: 0

README

gosocket

About:

  • A Simple Go Socket Framework

Installation:

$ go get -u github.com/golangpros/gosocket

Tutorial:

import "github.com/golangpros/gosocket"

func main() {
 	myhost := "127.0.0.1:8080"

 	ss, err := gosocket.NewSocketService(myhost)
	if err != nil {
		return
	}

	ss.SetHeartBeat(5*time.Second, 30*time.Second)

	ss.RegMessageHandler(HandleMessage)
	ss.RegConnectHandler(HandleConnect)
	ss.RegDisconnectHandler(HandleDisconnect)

	ss.Serv()
}

Thanks for contributors:

Documentation

Index

Constants

View Source
const (
	STUnknown = iota
	STInited
	STRunning
	STStop
)
View Source
const (
	MsgHeartbeat = iota
)

Variables

This section is empty.

Functions

func Encode

func Encode(msg *Message) ([]byte, error)

Types

type Conn

type Conn struct {
	// contains filtered or unexported fields
}

func NewConn

func NewConn(c net.Conn, hbInterval time.Duration, hbTimeout time.Duration) *Conn

func (*Conn) Close

func (c *Conn) Close()

func (*Conn) GetName

func (c *Conn) GetName() string

func (*Conn) SendMessage

func (c *Conn) SendMessage(msg *Message) error

type Message

type Message struct {
	// contains filtered or unexported fields
}

func Decode

func Decode(data []byte) (*Message, error)

func NewMessage

func NewMessage(msgID int32, data []byte) *Message

func (*Message) GetData

func (msg *Message) GetData() []byte

func (*Message) GetID

func (msg *Message) GetID() int32

func (*Message) String

func (msg *Message) String() string

func (*Message) Verify

func (msg *Message) Verify() bool

type Session

type Session struct {
	// contains filtered or unexported fields
}

func NewSession

func NewSession(conn *Conn) *Session

func (*Session) BindUserID

func (s *Session) BindUserID(uid string)

func (*Session) GetConn

func (s *Session) GetConn() *Conn

func (*Session) GetSessionID

func (s *Session) GetSessionID() string

func (*Session) GetSetting

func (s *Session) GetSetting(key string) interface{}

func (*Session) GetUserID

func (s *Session) GetUserID() string

func (*Session) SetConn

func (s *Session) SetConn(conn *Conn)

func (*Session) SetSetting

func (s *Session) SetSetting(key string, value interface{})

type SocketService

type SocketService struct {
	// contains filtered or unexported fields
}

func NewSocketService

func NewSocketService(laddr string) (*SocketService, error)

func (*SocketService) Broadcast

func (s *SocketService) Broadcast(msg *Message)

func (*SocketService) GetConnsCount

func (s *SocketService) GetConnsCount() int

func (*SocketService) GetStatus

func (s *SocketService) GetStatus() int

func (*SocketService) RegConnectHandler

func (s *SocketService) RegConnectHandler(handler func(*Session))

func (*SocketService) RegDisconnectHandler

func (s *SocketService) RegDisconnectHandler(handler func(*Session, error))

func (*SocketService) RegMessageHandler

func (s *SocketService) RegMessageHandler(handler func(*Session, *Message))

func (*SocketService) Serv

func (s *SocketService) Serv()

func (*SocketService) SetHeartBeat

func (s *SocketService) SetHeartBeat(hbInterval time.Duration, hbTimeout time.Duration) error

func (*SocketService) Stop

func (s *SocketService) Stop(reason string)

func (*SocketService) Unicast

func (s *SocketService) Unicast(sid string, msg *Message)

Jump to

Keyboard shortcuts

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