Documentation ¶
Index ¶
- Variables
- type ClosedError
- type Conn
- type Dialer
- type MessageType
- type OnCloseFunc
- type OnDataFunc
- type OnOpenFunc
- type Option
- func WithAsyncWrite(writeQueueSize int, writeForever bool) Option
- func WithBinary() Option
- func WithBufferSize(readBufferSize, writeBufferSize int) Option
- func WithClientHeader(header http.Header) Option
- func WithCompress(compressLevel int, compressThreshold int64) Option
- func WithDialer(dialer Dialer) Option
- func WithMaxFrameSize(maxFrameSize int64) Option
- func WithNoDelay(noDelay bool) Option
- func WithServeMux(serveMux *http.ServeMux) Option
- func WithServeTLS(tls *tls.Config) Option
- func WithServerHeader(header http.Header) Option
- func WithValidUTF8() Option
- type Websocket
- func (ws *Websocket) Close() error
- func (ws *Websocket) Listen(addr string) error
- func (ws *Websocket) Open(addr string) (conn Conn, err error)
- func (ws *Websocket) ServeHTTP(writer http.ResponseWriter, request *http.Request)
- func (ws *Websocket) UpgradeHTTP(writer http.ResponseWriter, request *http.Request) (conn Conn, err error)
Constants ¶
This section is empty.
Variables ¶
var ErrServerClosed = netty.ErrServerClosed
ErrServerClosed is returned by the Server call Shutdown or Close
Functions ¶
This section is empty.
Types ¶
type ClosedError ¶
ClosedError returned when peer has closed the connection with appropriate code and a textual reason.
type Conn ¶
type Conn interface { // Context returns the context of the connection. Context() context.Context // LocalAddr returns the local network address. LocalAddr() string // RemoteAddr returns the remote network address. RemoteAddr() string // Header returns the HTTP header on handshake request. Header() http.Header // SetDeadline sets the read and write deadlines associated // with the connection. It is equivalent to calling both // SetReadDeadline and SetWriteDeadline. SetDeadline(t time.Time) error // SetReadDeadline sets the deadline for future Read calls // and any currently-blocked Read call. // A zero value for t means Read will not time out. SetReadDeadline(t time.Time) error // SetWriteDeadline sets the deadline for future Write calls // and any currently-blocked Write call. // Even if write times out, it may return n > 0, indicating that // some of the data was successfully written. // A zero value for t means Write will not time out. SetWriteDeadline(t time.Time) error // Write writes a message to the connection. Write(message []byte) error // WriteClose write websocket close frame with code and close reason. WriteClose(code int, reason string) error // Close closes the connection. Close() error // Userdata returns the user-data. Userdata() interface{} // SetUserdata sets the user-data. SetUserdata(userdata interface{}) }
Conn is a websocket connection.
type Dialer ¶ added in v1.0.5
type Dialer interface { // Dial connects to the given address via the proxy. Dial(network, addr string) (c net.Conn, err error) }
Dialer is a means to establish a connection.
type MessageType ¶
type MessageType int
MessageType websocket message type
const ( // MsgText text message MsgText MessageType = iota // MsgBinary binary message MsgBinary )
type OnCloseFunc ¶
type OnDataFunc ¶
type OnOpenFunc ¶
type OnOpenFunc func(conn Conn)
type Option ¶
type Option func(*options)
func WithAsyncWrite ¶
WithAsyncWrite enable async write
func WithBufferSize ¶
WithBufferSize set the read/write buffer size
func WithClientHeader ¶ added in v1.0.4
WithClientHeader is an optional http.Header mapping that could be used to write additional headers to the handshake request.
func WithCompress ¶
WithCompress enable message compression with level, messages below the threshold will not be compressed.
func WithDialer ¶ added in v1.0.5
WithDialer specify the client to connect to the network via a dialer.
func WithMaxFrameSize ¶
WithMaxFrameSize set the maximum frame size
func WithNoDelay ¶
WithNoDelay controls whether the operating system should delay packet transmission in hopes of sending fewer packets (Nagle's algorithm). The default is true (no delay), meaning that data is sent as soon as possible after a Write.
func WithServeMux ¶
WithServeMux overwrite default http.ServeMux
func WithServerHeader ¶ added in v1.0.4
WithServerHeader is an optional http.Header mapping that could be used to write additional headers to the handshake response.
func WithValidUTF8 ¶
func WithValidUTF8() Option
WithValidUTF8 enable UTF-8 checks for text frames payload
type Websocket ¶
type Websocket struct { OnOpen OnOpenFunc OnData OnDataFunc OnClose OnCloseFunc // contains filtered or unexported fields }
func NewWebsocket ¶
NewWebsocket create websocket instance with options
func (*Websocket) ServeHTTP ¶ added in v1.0.5
func (ws *Websocket) ServeHTTP(writer http.ResponseWriter, request *http.Request)
func (*Websocket) UpgradeHTTP ¶
func (ws *Websocket) UpgradeHTTP(writer http.ResponseWriter, request *http.Request) (conn Conn, err error)
UpgradeHTTP upgrades http connection to the websocket connection