networking

package
v0.0.0-...-5b12917 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2017 License: GPL-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Encode

func Encode(packet Packet) []byte

Types

type Client

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

func NewClient

func NewClient() *Client

func (*Client) Close

func (c *Client) Close()

func (*Client) Connect

func (c *Client) Connect(addr string) error

func (*Client) GetBytesReceivedByEvent

func (c *Client) GetBytesReceivedByEvent() (byEvent map[string]int64)

func (*Client) GetBytesSentByEvent

func (c *Client) GetBytesSentByEvent() (byEvent map[string]int64)

func (*Client) PacketReceived

func (c *Client) PacketReceived(callback func(packet Packet))

func (*Client) WriteMessage

func (c *Client) WriteMessage(command string, data []byte)

type Network

type Network struct {
	emitter.EventEmitter
	// contains filtered or unexported fields
}

func NewNetwork

func NewNetwork() *Network

func (*Network) BroadcastEvent

func (n *Network) BroadcastEvent(name string, data []byte)

BroadcastEvent - trigger an event on all clients. If called on the client, this will trigger the event on the server.

func (*Network) BytesReceived

func (n *Network) BytesReceived() int64

func (*Network) BytesReceivedByCommand

func (n *Network) BytesReceivedByCommand() map[string]int64

func (*Network) BytesSent

func (n *Network) BytesSent() int64

func (*Network) BytesSentByCommand

func (n *Network) BytesSentByCommand() map[string]int64

func (*Network) ClientJoinedEvent

func (n *Network) ClientJoinedEvent(fn func(clientId string))

ClientJoinedEvent - register an event to trigger when a new client joins the server

func (*Network) ClientToken

func (n *Network) ClientToken() string

func (*Network) Close

func (n *Network) Close()

func (*Network) ConnectClient

func (n *Network) ConnectClient(addr string) error

func (*Network) FlushAllWriteBuffers

func (n *Network) FlushAllWriteBuffers()

func (*Network) FlushWriteBuffer

func (n *Network) FlushWriteBuffer(clientId string)

func (*Network) IsClient

func (n *Network) IsClient() bool

func (*Network) IsServer

func (n *Network) IsServer() bool

func (*Network) RegisterEvent

func (n *Network) RegisterEvent(name string, fn func(clientId string, data []byte))

RegisterEvent - register an event that will be triggered on clients and server. RegisterEvent should be used to register syncronous events

func (*Network) StartServer

func (n *Network) StartServer(port int)

func (*Network) TriggerEvent

func (n *Network) TriggerEvent(name, clientId string, data []byte)

TriggerEvent - Trigger an event to run on a particular client. If called on the client, this will trigger the event on the server.

func (*Network) TriggerOnServerAndClients

func (n *Network) TriggerOnServerAndClients(name string, data []byte)

CallOnServerAndClient - trigger an event on the server and on all client. If called on the client, this will trigger the event on the client and on the server.

func (*Network) Update

func (n *Network) Update(dt float64)

Update is used when using network in a fully syncronous manner. Update should not be called when using asyncronous (channel) based event handling

type Packet

type Packet struct {
	Token   string
	Command string
	Data    []byte
}

func Decode

func Decode(data []byte, i int) (Packet, error, int)

type Server

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

func NewServer

func NewServer() *Server

func (*Server) BroadcastMessage

func (s *Server) BroadcastMessage(command string, data []byte)

func (*Server) ClientJoinedEvent

func (s *Server) ClientJoinedEvent(callback func(clientId string))

func (*Server) Close

func (s *Server) Close()

func (*Server) FlushAllWriteBuffers

func (s *Server) FlushAllWriteBuffers()

FlushAllWriteBuffers - send all buffered messages immediately for all sessions

func (*Server) FlushWriteBuffer

func (s *Server) FlushWriteBuffer(token string)

FlushWriteBuffer - send all buffered messages immediately

func (*Server) Listen

func (s *Server) Listen(port int)

func (*Server) PacketReceived

func (s *Server) PacketReceived(callback func(packet Packet))

func (*Server) WriteMessage

func (s *Server) WriteMessage(packet Packet)

type Session

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

func NewSession

func NewSession(addr *net.UDPAddr) *Session

Jump to

Keyboard shortcuts

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