func (ws *Conn) Write(msg []byte) (n int, err error) {
	ws.wio.Lock()
	defer ws.wio.Unlock()
	w, err := ws.frameWriterFactory.NewFrameWriter(ws.PayloadType)
	if err != nil {
		return 0, err
	}
	n, err = w.Write(msg)
	w.Close()
	return n, err
}
Write implements the io.Writer interface:
it writes data as a frame to the WebSocket connection.
package websocket  
import (
	"bufio"
	"crypto/tls"
	"encoding/json"
	"errors"
	"io"
	"io/ioutil"
	"net"
	"net/http"
	"net/url"
	"sync"
	"time"
)
const (
	ProtocolVersionHybi13    = 13
	ProtocolVersionHybi      = ProtocolVersionHybi13
	SupportedProtocolVersion = "13"
	ContinuationFrame = 0
	TextFrame         = 1
	BinaryFrame       = 2
	CloseFrame        = 8
	PingFrame         = 9
	PongFrame         = 10
	UnknownFrame      = 255
)
type ProtocolError struct {
	ErrorString string
}
func (err *ProtocolError) Error() string { return err.ErrorString }
var (
	ErrBadProtocolVersion   = &ProtocolError{"bad protocol version"}
	ErrBadScheme            = &ProtocolError{"bad scheme"}
	ErrBadStatus            = &ProtocolError{"bad status"}
	ErrBadUpgrade           = &ProtocolError{"missing or bad upgrade"}
	ErrBadWebSocketOrigin   = &ProtocolError{"missing or bad WebSocket-Origin"}
	ErrBadWebSocketLocation = &ProtocolError{"missing or bad WebSocket-Location"}
	ErrBadWebSocketProtocol = &ProtocolError{"missing or bad WebSocket-Protocol"}
	ErrBadWebSocketVersion  = &ProtocolError{"missing or bad WebSocket Version"}
	ErrChallengeResponse    = &ProtocolError{"mismatch challenge/response"}
	ErrBadFrame             = &ProtocolError{"bad frame"}
	ErrBadFrameBoundary     = &ProtocolError{"not on frame boundary"}
	ErrNotWebSocket         = &ProtocolError{"not websocket protocol"}
	ErrBadRequestMethod     = &ProtocolError{"bad method"}
	ErrNotSupported         = &ProtocolError{"not supported"}
)
type Addr struct {
	*url.URL
}
func (addr *Addr) Network() string { return "websocket" }
type Config struct {
	Location *url.URL
	Origin *url.URL
	Protocol []string
	Version int
	TlsConfig *tls.Config
	Header http.Header
	handshakeData map[string]string
}
type serverHandshaker interface {
	ReadHandshake(buf *bufio.Reader, req *http.Request) (code int, err error)
	AcceptHandshake(buf *bufio.Writer) (err error)
	NewServerConn(buf *bufio.ReadWriter, rwc io.ReadWriteCloser, request *http.Request) (conn *Conn)
}
type frameReader interface {
	io.Reader
	PayloadType() byte
	HeaderReader() io.Reader
	TrailerReader() io.Reader
	Len() int
}
type frameReaderFactory interface {
	NewFrameReader() (r frameReader, err error)
}
type frameWriter interface {
	io.WriteCloser
}
type frameWriterFactory interface {
	NewFrameWriter(payloadType byte) (w frameWriter, err error)
}
type frameHandler interface {
	HandleFrame(frame frameReader) (r frameReader, err error)
	WriteClose(status int) (err error)
}
type Conn struct {
	config  *Config
	request *http.Request
	buf *bufio.ReadWriter
	rwc io.ReadWriteCloser
	rio sync.Mutex
	frameReaderFactory
	frameReader
	wio sync.Mutex
	frameWriterFactory
	frameHandler
	PayloadType        byte
	defaultCloseStatus int
}
func (ws *Conn) Read(msg []byte) (n int, err error) {
	ws.rio.Lock()
	defer ws.rio.Unlock()
again:
	if ws.frameReader == nil {
		frame, err := ws.frameReaderFactory.NewFrameReader()
		if err != nil {
			return 0, err
		}
		ws.frameReader, err = ws.frameHandler.HandleFrame(frame)
		if err != nil {
			return 0, err
		}
		if ws.frameReader == nil {
			goto again
		}
	}
	n, err = ws.frameReader.Read(msg)
	if err == io.EOF {
		if trailer := ws.frameReader.TrailerReader(); trailer != nil {
			io.Copy(ioutil.Discard, trailer)
		}
		ws.frameReader = nil
		goto again
	}
	return n, err
}