working

package module
v0.0.0-...-424b381 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2024 License: MIT Imports: 7 Imported by: 0

README

Go Networking Thingy Calcopod

More information and documentation will be added soon lol

Documentation

Index

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

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 NewClient

func NewClient(ctx context.Context, cancel context.CancelFunc) *Client

func (*Client) GetAddress

func (c *Client) GetAddress() string

func (*Client) PollStopped

func (s *Client) PollStopped(duration time.Duration) <-chan struct{}

func (*Client) Send

func (c *Client) Send(bytes []byte)

func (*Client) Start

func (c *Client) Start(server_address string)

func (*Client) Stop

func (c *Client) Stop()

TODO(calco): add this function lmao TODO(calco): Disconnect from server

type ClientId

type ClientId int

func (*ClientId) Next

func (c *ClientId) Next() ClientId

func (*ClientId) PeekNext

func (c *ClientId) PeekNext() ClientId

type ClientState

type ClientState uint
const (
	ClientNone ClientState = iota
	ClientStarted
	ClientStopping
	ClientStopped
)

type DummyClient

type DummyClient struct {
	ClientId ClientId
	Address  *net.UDPAddr
}

type DummyServer

type DummyServer struct {
	Address *net.UDPAddr
}

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 NewServer

func NewServer(ctx context.Context, cancel context.CancelFunc, ip string, port uint) *Server

func (*Server) Broadcast

func (s *Server) Broadcast(bytes []byte) (*DummyClient, int, error)

func (*Server) GetAddress

func (s *Server) GetAddress() string

func (*Server) HasClientId

func (s *Server) HasClientId(clientId ClientId) (*DummyClient, bool)

func (*Server) PollStopped

func (s *Server) PollStopped(duration time.Duration) <-chan struct{}

func (*Server) SendToClient

func (s *Server) SendToClient(clientId ClientId, bytes []byte) (int, error)

func (*Server) Start

func (s *Server) Start()

func (*Server) Stop

func (s *Server) Stop()

TODO(calco): Disconnect clients from server

type ServerState

type ServerState uint
const (
	ServerNone ServerState = iota
	ServerStarted
	ServerStopping
	ServerStopped
)

Directories

Path Synopsis
cmd
chat command
pkg

Jump to

Keyboard shortcuts

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