server

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: May 6, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AbstractSession

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

func (*AbstractSession) GetUserData

func (s *AbstractSession) GetUserData() any

func (*AbstractSession) SetUserData

func (s *AbstractSession) SetUserData(d any)

type Packet

type Packet struct {
	Type PacketType
	Data []byte
	// contains filtered or unexported fields
}

Packet 连接状态也通过该数据包回调

func (*Packet) ToString

func (p *Packet) ToString() string

type PacketType

type PacketType int
const (
	PacketTypeConnected   PacketType = 0 // 连接成功
	PacketTypeConnectLost PacketType = 1 // 连接断开
	PacketTypeData        PacketType = 2 // 数据包
)

func (PacketType) ToString

func (p PacketType) ToString() string

type Server

type Server interface {
	core.Subject[*Packet]
	Open() error
	Write(*Packet) error
	Close()
}

Server 服务端接口

type Session

type Session interface {
	Write(packet *Packet) error
	GetAddress() string
	SetUserData(d any)
	GetUserData() any
}

Session 会话接口

type TcpServer

type TcpServer struct {
	core.AbstractSubject[*Packet]
	// contains filtered or unexported fields
}

func NewTcpServer

func NewTcpServer(address string) *TcpServer

func (*TcpServer) Close

func (s *TcpServer) Close()

func (*TcpServer) Open

func (s *TcpServer) Open() error

func (*TcpServer) Write

func (s *TcpServer) Write(data *Packet) error

type TcpSession

type TcpSession struct {
	AbstractSession
	// contains filtered or unexported fields
}

func (*TcpSession) GetAddress

func (s *TcpSession) GetAddress() string

func (*TcpSession) Write

func (s *TcpSession) Write(packet *Packet) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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