Documentation ¶
Overview ¶
Robust Go and Javascript Socket Library. This library is thread-safe.
Index ¶
- Variables
- func Block(b bool)
- func OnNewSocket(f OnNewSocketFunc)
- func RunRouter()
- func WriteBroadcast(event string, msg string)
- type OnCloseFunc
- type OnNewSocketFunc
- type OnReadFunc
- type Router
- type Socket
- func (s *Socket) Close()
- func (s *Socket) DiscardRead()
- 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 ¶
This section is empty.
Variables ¶
var ( ErrSocketClosed = errors.New("the socket connection is closed.") ErrReadTimeout = errors.New("the read timeout was reached.") )
Public errors:
var Server = Router{ // contains filtered or unexported fields }
Functions ¶
func OnNewSocket ¶
func OnNewSocket(f OnNewSocketFunc)
OnNewSocket sets the event function which is triggered if a new socket connection was made.
func WriteBroadcast ¶
Types ¶
type OnCloseFunc ¶
type OnCloseFunc func()
type OnNewSocketFunc ¶
type OnNewSocketFunc func(s *Socket)
type OnReadFunc ¶
type OnReadFunc func(data string)
type Socket ¶
type Socket struct {
// contains filtered or unexported fields
}
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 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 |
---|---|
Backend socket implementations.
|
Backend 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. |
Log backend used by the socket library.
|
Log backend used by the socket library. |
sample
|
|
Socket utilities.
|
Socket utilities. |