func (s *WebSocketServer) Addr() net.Addr {
	return s.listener.Addr()
}
Addr returns the server's network address.
package transport
import (
	"crypto/tls"
	"fmt"
	"net"
	"net/http"
	"gopkg.in/tomb.v2"
)
type WebSocketServer struct {
	listener net.Listener
	upgrader *WebSocketUpgrader
	incoming chan *WebSocketConn
	tomb     tomb.Tomb
}
func NewWebSocketServer(listener net.Listener, fallback http.Handler) *WebSocketServer {
	ws := &WebSocketServer{
		listener: listener,
		upgrader: NewWebSocketUpgrader(fallback),
		incoming: make(chan *WebSocketConn),
	}
	ws.tomb.Go(func() error {
		return http.Serve(ws.listener, http.HandlerFunc(ws.handler))
	})
	return ws
}
func CreateWebSocketServer(address string, fallback http.Handler) (*WebSocketServer, error) {
	listener, err := net.Listen("tcp", address)
	if err != nil {
		return nil, err
	}
	return NewWebSocketServer(listener, fallback), nil
}
func CreateSecureWebSocketServer(address string, config *tls.Config, fallback http.Handler) (*WebSocketServer, error) {
	listener, err := tls.Listen("tcp", address, config)
	if err != nil {
		return nil, err
	}
	return NewWebSocketServer(listener, fallback), nil
}
func (s *WebSocketServer) handler(w http.ResponseWriter, r *http.Request) {
	conn, _ := s.upgrader.Upgrade(w, r)
	if conn == nil {
		return
	}
	select {
	case s.incoming <- conn:
	case <-s.tomb.Dying():
		_ = conn.Close()
	}
}
func (s *WebSocketServer) Accept() (Conn, error) {
	select {
	case conn := <-s.incoming:
		return conn, nil
	case <-s.tomb.Dying():
		return nil, s.tomb.Err()
	}
}
func (s *WebSocketServer) Close() error {
	s.tomb.Kill(fmt.Errorf("closed"))
	err := s.listener.Close()
	if err != nil {
		return err
	}
	return nil
}