Documentation ¶
Overview ¶
Package glue - Robust Go and Javascript Socket Library. This library is thread-safe.
Index ¶
- Constants
- Variables
- func Block(b bool)
- func OnNewSocket(f OnNewSocketFunc)
- func Release()
- type Channel
- type OnCloseFunc
- type OnNewSocketFunc
- type OnReadFunc
- type Socket
- func (s *Socket) Channel(name string) *Channel
- func (s *Socket) Close()
- func (s *Socket) DiscardRead()
- func (s *Socket) ID() string
- func (s *Socket) IsClosed() bool
- func (s *Socket) OnClose(f OnCloseFunc)
- func (s *Socket) OnRead(f OnReadFunc)
- func (s *Socket) Read(timeout ...time.Duration) (string, error)
- func (s *Socket) RemoteAddr() string
- func (s *Socket) UserAgent() string
- func (s *Socket) Write(data string)
Constants ¶
const (
// Version holds the Glue Socket Protocol Version as string.
Version = "1.2.0"
)
Public ######
Variables ¶
var ( ErrSocketClosed = errors.New("the socket connection is closed") ErrReadTimeout = errors.New("the read timeout was reached") )
Public errors:
Functions ¶
func OnNewSocket ¶
func OnNewSocket(f OnNewSocketFunc)
OnNewSocket sets the event function which is triggered if a new socket connection was made. The event function must not block! As soon as the event function returns, the socket is added to the active sockets map.
Types ¶
type Channel ¶
type Channel struct {
// contains filtered or unexported fields
}
A Channel is a separate communication channel.
func (*Channel) DiscardRead ¶
func (c *Channel) DiscardRead()
DiscardRead ignores and discars the data received from this channel. Call this method during initialization, if you don't read any data from this channel. If received data is not discarded, then the read buffer will block as soon as it is full, which will also block the keep-alive mechanism of the socket. The result would be a closed socket...
func (*Channel) OnRead ¶
func (c *Channel) OnRead(f OnReadFunc)
OnRead sets the function which is triggered if new data is received on the channel. If this event function based method of reading data from the socket is used, then don't use the socket Read method. Either use the OnRead or the Read approach.
func (*Channel) Read ¶
Read the next message from the channel. This method is blocking. One variadic argument sets a timeout duration. If no timeout is specified, this method will block forever. ErrSocketClosed is returned, if the socket connection is closed. ErrReadTimeout is returned, if the timeout is reached.
type Socket ¶
type Socket struct { // A Value is a placeholder for custom data. // Use this to attach socket specific data. Value interface{} // contains filtered or unexported fields }
A Socket represents a single socket connections to a client.
func Sockets ¶
func Sockets() []*Socket
Sockets returns a list of all current connected sockets. Hint: Sockets are added to the active sockets list after the OnNewSocket event function is called.
func (*Socket) Channel ¶
Channel returns the corresponding channel value specified by the name. If no channel value exists for the given name, a new channel is created. Multiple calls to Channel with the same name, will always return the same channel value pointer.
func (*Socket) DiscardRead ¶
func (s *Socket) DiscardRead()
DiscardRead ignores and discars the data received from the client. Call this method during initialization, if you don't read any data from the socket. If received data is not discarded, then the read buffer will block as soon as it is full, which will also block the keep-alive mechanism of the socket. The result would be a closed socket...
func (*Socket) OnClose ¶
func (s *Socket) OnClose(f OnCloseFunc)
OnClose sets the functions which is triggered if the socket connection is closed.
func (*Socket) OnRead ¶
func (s *Socket) OnRead(f OnReadFunc)
OnRead sets the function which is triggered if new data is received. If this event function based method of reading data from the socket is used, then don't use the socket Read method. Either use the OnRead or the Read approach.
func (*Socket) Read ¶
Read the next message from the socket. This method is blocking. One variadic argument sets a timeout duration. If no timeout is specified, this method will block forever. ErrSocketClosed is returned, if the socket connection is closed. ErrReadTimeout is returned, if the timeout is reached.
func (*Socket) RemoteAddr ¶
RemoteAddr returns the remote address of the client.
Directories ¶
Path | Synopsis |
---|---|
Package backend provides various socket implementations.
|
Package backend provides various socket implementations. |
closer
Emit a close function only once, also if called multiple times.
|
Emit a close function only once, also if called multiple times. |
Package log holds the log backend used by the socket library.
|
Package log holds the log backend used by the socket library. |
sample
|
|
Package utils provides utilities for the glue socket implementation.
|
Package utils provides utilities for the glue socket implementation. |