server

package
v0.0.0-...-8f0d097 Latest Latest
Warning

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

Go to latest
Published: May 22, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Version string = "0.1.0"

Version - Used to identify specific versions of the CloudLink Golang server.

View Source
var WebsocketUpgrader = websocket.Upgrader{
	ReadBufferSize:  2048,
	WriteBufferSize: 2048,

	CheckOrigin: func(r *http.Request) bool {
		return true
	},
}

WebsocketUpgrader is used to upgrade HTTP(s) requests into websocket connections.

Functions

func Init

func Init()

Init initializes the CloudLink server.

func MulticastMessage

func MulticastMessage(clients ClientList, message schemas.CloudlinkRootSchema)

MulticastMessage will send a message to multiple clients.

func ServeWS

func ServeWS(host string)

ServeWS starts the CloudLink server in insecure (ws://) mode. You must call initServer beforehand to use this function.

func ServeWSS

func ServeWSS(host string, cert string, key string)

ServeWSS starts the CloudLink server in secure (wss://) mode. You must have a certificate file (cert, or cert.pem) and a private key (key, or key.pem) file present and trusted by your client(s) before running.

You must call initServer beforehand to use this function.

func UnicastMessage

func UnicastMessage(client Client, message schemas.CloudlinkRootSchema)

UnicastMessage will send a message to a single client.

Types

type Client

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

Client is a websocket client.

func NewClient

func NewClient(conn *websocket.Conn, manager *Manager) *Client

NewClient is used to initialize a new Client with all attributes initialized.

func (*Client) MessageHandler

func (c *Client) MessageHandler(mgr *Manager)

Main function for handling websocket messages.

type ClientList

type ClientList map[*Client]Client

ClientList is a map used to keep track of clients.

type Manager

type Manager struct {

	// Used to lock states before editing a client.
	sync.RWMutex
	// contains filtered or unexported fields
}

Manager is used to store all values for each client.

func NewManager

func NewManager() *Manager

NewManager is used to create a manager struct and initialize its values.

func (*Manager) AddClient

func (m *Manager) AddClient(client *Client)

AddClient adds a client to the ClientList

func (*Manager) RemoveClient

func (m *Manager) RemoveClient(client *Client)

RemoveClient removes a client from the ClientList and cleans things up

func (*Manager) Server

func (mgr *Manager) Server(w http.ResponseWriter, r *http.Request)

Server is used to handle new connections, create managers, and process messages.

Jump to

Keyboard shortcuts

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