Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type WebSockListener ¶
type WebSockListener struct {
// contains filtered or unexported fields
}
WebSockListener implements net.Listener and provides connections that are incoming websocket connections
func NewWebSocketListener ¶
func NewWebSocketListener(ctx context.Context, opts *websocket.AcceptOptions) *WebSockListener
NewWebSocketListener constructs a new WebSockListener, the provided context is for the lifetime of the listener. 初始化的时候加了一个 websocket.Accept时的 opts 参数
// websocket.AcceptOptions 参数 type AcceptOptions struct { Subprotocols []string // 支持的子协议 InsecureSkipVerify bool // 是否跳过 SSL/TLS 证书的验证 OriginPatterns []string // 跨域请求设置 []string("*")表示允许所有来源 也可以[]string{"*://example.com", "http://example*"} 满足一个即可访问 CompressionMode CompressionMode // 压缩模式 websocket.Compression... 有三种 详见websocket源码注释 CompressionThreshold int // 压缩数据的最低字节数阈值 }
func (*WebSockListener) Accept ¶
func (wsl *WebSockListener) Accept() (net.Conn, error)
Accept fulfills the net.Listener interface and returns net.Conn that are incoming websockets
func (*WebSockListener) Addr ¶
func (wsl *WebSockListener) Addr() net.Addr
RemoteAddr returns a dummy websocket address to satisfy net.Listener
func (*WebSockListener) ServeHTTP ¶
func (wsl *WebSockListener) ServeHTTP(wtr http.ResponseWriter, req *http.Request)
ServeHTTP is a method that is mean to be used as http.HandlerFunc to accept inbound HTTP requests that are websocket connections
Click to show internal directories.
Click to hide internal directories.