network

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

func NewClient

func NewClient(addr string) (*Client, error)

func (*Client) Close

func (c *Client) Close()

func (*Client) Errors

func (c *Client) Errors() <-chan error

func (*Client) NextMessage

func (c *Client) NextMessage() <-chan Message

func (*Client) ReadLoop

func (c *Client) ReadLoop()

func (*Client) Send

func (c *Client) Send(m Message) error

func (*Client) SendJoin

func (c *Client) SendJoin(name string) error

func (*Client) SendStart

func (c *Client) SendStart(text string, countdown int) error

func (*Client) SendUpdate

func (c *Client) SendUpdate(name string, wpm int, progress float64, completed bool) error

type DisconnectPayload

type DisconnectPayload struct {
	PlayerName string `json:"player_name"`
}

type JoinPayload

type JoinPayload struct {
	PlayerName string `json:"player_name"`
}

type Message

type Message struct {
	Type    MessageType     `json:"type"`
	Payload json.RawMessage `json:"payload"`
}

type MessageType

type MessageType string
const (
	MsgJoin   MessageType = "join"
	MsgStart  MessageType = "start"
	MsgUpdate MessageType = "update"
	MsgBye    MessageType = "bye"
)

type Server

type Server struct {
	Clients map[net.Conn]string
	Mu      sync.Mutex
}

func NewServer

func NewServer() *Server

func (*Server) Broadcast

func (s *Server) Broadcast(msg Message)

func (*Server) HandleJoin

func (s *Server) HandleJoin(conn net.Conn)

func (*Server) HandleMessage

func (s *Server) HandleMessage(sender net.Conn, msg Message)

func (*Server) Start

func (s *Server) Start(port string)

type StartPayload

type StartPayload struct {
	Text      string `json:"text"`
	Countdown int    `json:"countdown"`
}

type UpdatePayload

type UpdatePayload struct {
	PlayerName string  `json:"player_name"`
	Progress   float64 `json:"progress"`
	WPM        int     `json:"wpm"`
	Completed  bool    `json:"completed"`
}

Jump to

Keyboard shortcuts

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