示例#1
0
// Connect to a Beam server over a Websocket connection as a client
func NewSender(wsConn *websocket.Conn) (beam.Sender, error) {
	session, err := http2.NewStreamSession(ws.NewConnection(wsConn))
	if err != nil {
		return nil, err
	}
	return session, nil
}
示例#2
0
func (u *Upgrader) Upgrade(w http.ResponseWriter, r *http.Request, responseHeader http.Header) (*http2.Server, error) {
	wsConn, err := u.Upgrader.Upgrade(w, r, responseHeader)
	if err != nil {
		return nil, err
	}

	netConn := ws.NewConnection(wsConn)
	server, err := http2.NewServer(netConn)
	if err != nil {
		netConn.Close()
		return nil, err
	}

	return server, nil
}