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 ¶
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 ¶
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) 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) SendString ¶
SendString() sends a message to the websocket.
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.