sgs

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

README

SGS - Simple Game Server

This is a simple game server written in Golang. You can adopt it to your needs for small multiplayer games.

How it works

You should provide only two funcs for SGS.

The first is handler function - it is called in separated goroutines on every incoming data packet. You will have netip.AddrPort, io.Reader and io.Writer as arguments to provide your own logic. Here netip.AddrPort is client's address, Reader holds incoming from client request data and Writer for your response to this client if needed.

type Handler interface {  
    ServeUDP(netip.AddrPort, io.Reader, io.Writer)  
}

The second is sender function. This function also runs in a separate goroutine and used to send the same data to many clients. SGS sends data to clients in separated goroutines .

type Sender interface {  
    Send() ([]netip.AddrPort, io.Reader)  
}

Sender timeout

At this time you can't call sender function when you want but to provide better game logic you can set timeout for periodic calls.

Protocols

SGS works only with UDP but we have future plans to provide TCP for non-game data.

$ go get github.com/oktavarium/sgs

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrConflict = errors.New("client already exists")
View Source
var ErrNotFound = errors.New("no such client")

Functions

This section is empty.

Types

type Handler

type Handler interface {
	ServeUDP(netip.AddrPort, io.Reader, io.Writer)
}

type HandlerFunc

type HandlerFunc func(netip.AddrPort, io.Reader, io.Writer)

func (HandlerFunc) ServeUDP

func (f HandlerFunc) ServeUDP(addr netip.AddrPort, r io.Reader, w io.Writer)

type SGS

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

func NewServer

func NewServer(ctx context.Context,
	addr string,
	senderTimeout time.Duration,
	handler Handler,
	sender Sender,
) SGS

func (*SGS) ListenAndServe

func (s *SGS) ListenAndServe() (err error)

type Sender

type Sender interface {
	Send() ([]netip.AddrPort, io.Reader)
}

type SenderFunc

type SenderFunc func() ([]netip.AddrPort, io.Reader)

func (SenderFunc) Send

func (f SenderFunc) Send() ([]netip.AddrPort, io.Reader)

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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