tcp_server

package
v1.7.1 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BinaryType byte = iota
	StringType
)

Payload type

View Source
const MaxPacketSize uint32 = 10 << 20 // 10MBytes
View Source
const Timeout = 30 // seconds

Variables

View Source
var ErrMaxPacketSize = errors.New("maximum packet size exceeded")

Functions

func RunTcpTimer

func RunTcpTimer()

Types

type Binary

type Binary []byte

func (*Binary) Bytes

func (b *Binary) Bytes() []byte

func (*Binary) ReadFrom

func (b *Binary) ReadFrom(r io.Reader) (int64, error)

func (*Binary) String

func (b *Binary) String() string

func (*Binary) WriteTo

func (b *Binary) WriteTo(w io.Writer) (int64, error)

type Client

type Client struct {
	Conn          net.Conn
	ServerManager *ServerManager
	Name          string
	Uuid          string
	LastTimeSeen  time.Time
}

type Payload

type Payload interface {
	io.ReaderFrom
	io.WriterTo
	Bytes() []byte
	String() string
}

type Server

type Server struct {
	Address string // Address to open connection: localhost:9999
	Clients map[string]*Client
}

type ServerManager

type ServerManager struct {
	TcpServer *Server
	Mutex     *sync.Mutex
}

func NewServer

func NewServer(serverAddr string) *ServerManager

Singleton pattern

func (*ServerManager) Listen

func (s *ServerManager) Listen()

func (*ServerManager) OnClientConnectionClosed

func (s *ServerManager) OnClientConnectionClosed(c *Client, err error)

type String

type String string

func (*String) Bytes

func (s *String) Bytes() []byte

func (*String) ReadFrom

func (s *String) ReadFrom(r io.Reader) (int64, error)

func (*String) String

func (s *String) String() string

func (*String) WriteTo

func (s *String) WriteTo(w io.Writer) (int64, error)

Jump to

Keyboard shortcuts

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