Documentation
¶
Index ¶
- Constants
- func Bool2byte(b bool) byte
- func Byte2bool(b byte) bool
- type Client
- type ClientId
- type ClientState
- type DummyClient
- type DummyServer
- type EventClientPacket
- type Server
- func (s *Server) Broadcast(bytes []byte) (*DummyClient, int, error)
- func (s *Server) GetAddress() string
- func (s *Server) HasClientId(clientId ClientId) (*DummyClient, bool)
- func (s *Server) PollStopped(duration time.Duration) <-chan struct{}
- func (s *Server) SendToClient(clientId ClientId, bytes []byte) (int, error)
- func (s *Server) Start()
- func (s *Server) Stop()
- type ServerState
Constants ¶
View Source
const CLIENT_ID_NONE = -1
View Source
const CONNECTION_TIMEOUT_DELAY = 3 * time.Second
View Source
const MAX_STREAM_SIZE = 2048
Variables ¶
This section is empty.
Functions ¶
func Bool2byte ¶
Taken from https://0x0f.me/blog/golang-compiler-optimization/
func Byte2bool ¶
Adapted from https://0x0f.me/blog/golang-compiler-optimization/
Types ¶
type Client ¶
type Client struct {
// TODO(calco): Maybe make this a single net.UDPAddr
// IP string
Port uint
State ClientState
IsOwner bool
ClientId ClientId
Connection *net.UDPConn
DataStream []byte
Server DummyServer
// Callbacks
OnStarted actions.Action
OnStopped actions.Action
OnConnected actions.Action1[*DummyServer]
OnDiconnected actions.Action1[*DummyServer]
OnPacketReceived actions.Action2[int, []byte]
// contains filtered or unexported fields
}
func (*Client) GetAddress ¶
func (*Client) PollStopped ¶
type ClientState ¶
type ClientState uint
const ( ClientNone ClientState = iota ClientStarted ClientStopping ClientStopped )
type DummyClient ¶
type DummyServer ¶
type EventClientPacket ¶
type EventClientPacket struct {
// TODO(calco): Maybe send just the client id to make it safer ???
Client *DummyClient
Length int
}
TODO(calco): Should also send the data but for now I won't ???
type Server ¶
type Server struct {
// TODO(calco): Maybe make this a single net.UDPAddr
IP string
Port uint
State ServerState
Connection *net.UDPConn
DataStream []byte
Clients []DummyClient
Owner ClientId
CurrClientId ClientId
// Callbacks
OnStarted actions.Action
OnStopped actions.Action
OnClientConnected actions.Action1[*DummyClient]
OnClientDiconnected actions.Action1[*DummyClient]
OnPacketReceived actions.Action3[*DummyClient, int, []byte]
// contains filtered or unexported fields
}
func (*Server) GetAddress ¶
func (*Server) HasClientId ¶
func (s *Server) HasClientId(clientId ClientId) (*DummyClient, bool)
func (*Server) PollStopped ¶
func (*Server) SendToClient ¶
type ServerState ¶
type ServerState uint
const ( ServerNone ServerState = iota ServerStarted ServerStopping ServerStopped )
Click to show internal directories.
Click to hide internal directories.