websocket
最后更新于:2022-04-02 02:46:59
[TOC]
## 推荐库
```
https://godoc.org/github.com/gorilla/websocket
https://godoc.org/nhooyr.io/websocket
```
## 语法
### Func
```
func Origin(config *Config, req *http.Request) (*url.URL, error)
```
### Type
```
type Addr
func (addr *Addr) Network() string
type Codec
func (cd Codec) Receive(ws *Conn, v interface{}) (err error)
func (cd Codec) Send(ws *Conn, v interface{}) (err error)
type Config
func NewConfig(server, origin string) (config *Config, err error)
type Conn
func Dial(url_, protocol, origin string) (ws *Conn, err error)
func DialConfig(config *Config) (ws *Conn, err error)
func NewClient(config *Config, rwc io.ReadWriteCloser) (ws *Conn, err error)
func (ws *Conn) Close() error
func (ws *Conn) Config() *Config
func (ws *Conn) IsClientConn() bool
func (ws *Conn) IsServerConn() bool
func (ws *Conn) LocalAddr() net.Addr
func (ws *Conn) Read(msg []byte) (n int, err error)
func (ws *Conn) RemoteAddr() net.Addr
func (ws *Conn) Request() *http.Request
func (ws *Conn) SetDeadline(t time.Time) error
func (ws *Conn) SetReadDeadline(t time.Time) error
func (ws *Conn) SetWriteDeadline(t time.Time) error
func (ws *Conn) Write(msg []byte) (n int, err error)
type Handler
func (h Handler) ServeHTTP(w http.ResponseWriter, req *http.Request)
type Server
func (s Server) ServeHTTP(w http.ResponseWriter, req *http.Request)
```
## 示例
';