goSocketServer

package module
v0.0.0-...-bad906c Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2013 License: MIT Imports: 3 Imported by: 2

README

goSocketServer

Documentation

Overview

goSocketServer is a simple wrapper for the go.net/websocket library

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Socket

type Socket struct {
	Connection *websocket.Conn
	// contains filtered or unexported fields
}

Socket is a simple structure that wraps the functionality of a websocket.Conn, allowing a websocket to be registered with a server in this library.

func NewSocket

func NewSocket(ws *websocket.Conn) Socket

NewSocket() creates a new Socket structure that wraps the websocket. The unique ID will be 0 and is assigned when the Socket is registered with a server.

func (*Socket) Disconnect

func (s *Socket) Disconnect()

Disconnect() causes the default server in this library to stop monitoring the Socket

func (*Socket) GetId

func (s *Socket) GetId() int

GetID() returns the unique id of the websocket.

func (*Socket) Handle

func (s *Socket) Handle()

Handle() is a blocking function that handles all communication with the websocket as defined by the callback functions provided to the server. When calling Handle() as a thread, take care to ensure the websocket is not closed by your application.

func (*Socket) Register

func (s *Socket) Register()

Register() causes the default server in this library to start monitoring the Socket

func (*Socket) SendBytes

func (s *Socket) SendBytes(message []byte)

SendBytes() sends a message to the websocket.

func (*Socket) SendString

func (s *Socket) SendString(message string)

SendString() sends a message to the websocket.

func (*Socket) Write

func (s *Socket) Write(p []byte) (n int, err error)

Write() is called when a message is received from the websocket. Write() DOES NOT send a message to the websocket. To send a message to the websocket use SendBytes() or SendString().

type SocketServer

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

SocketServer manages connecting, disconnecting, and handling messages from all websockets registered with it.

var Server SocketServer

Server is the default SocketServer for this library. Unless you know what you are doing, it is recommended you use this default server for all websockets in your application.

func (*SocketServer) OnConnect

func (s *SocketServer) OnConnect(function func(*Socket))

OnConnect() sets a callback function that will be called whenever a new websocket connects to the server. The connecting websocket will be wrapped in this library's Socket struct and passed to the callback function as a parameter.

func (*SocketServer) OnDisconnect

func (s *SocketServer) OnDisconnect(function func(*Socket))

OnDisconnect() sets a callback function that will be called whenever a websocket disconnects from the server. The Socket struct mapped to this websocket will be passed to the callback function as a parameter.

func (*SocketServer) OnMessage

func (s *SocketServer) OnMessage(function func(*Socket, []byte))

OnMessage() sets a callback function that will be called whenever the server recieves a message from the websocket. The Socket struct mapped to the websocket that sent a message and the []byte array representing the message will be passed to the callback function as parameters.

func (*SocketServer) WriteAll

func (s *SocketServer) WriteAll(message string)

WriteAll() sends the string "message" to all sockets currently connected to the server.

Jump to

Keyboard shortcuts

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