From d56b51065fc2aa4d54e159973abe79db90a65123 Mon Sep 17 00:00:00 2001 From: Smile Rex Date: Tue, 10 Mar 2026 01:09:59 +0300 Subject: [PATCH] new quic release [chat tests] 6 --- main.go | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/main.go b/main.go index e85d6c9..f860b3e 100644 --- a/main.go +++ b/main.go @@ -6,6 +6,7 @@ import ( "log" "net/http" + "github.com/quic-go/quic-go/http3" "github.com/quic-go/webtransport-go" ) @@ -13,13 +14,13 @@ func main() { mux := http.NewServeMux() - wm := &webtransport.Server{ + wt := &webtransport.Server{ CheckOrigin: func(r *http.Request) bool { return true }, } mux.HandleFunc("/chat", func(w http.ResponseWriter, r *http.Request) { - session, err := wm.Upgrade(w, r) + session, err := wt.Upgrade(w, r) if err != nil { log.Println("upgrade error:", err) return @@ -28,12 +29,12 @@ func main() { go handleChatSession(session) }) - server := &http.Server{ + server := http3.Server{ Addr: ":8080", Handler: mux, } - fmt.Println("Server started") + fmt.Println("HTTP/3 server started") log.Fatal(server.ListenAndServe()) } @@ -41,25 +42,20 @@ func main() { func handleChatSession(session *webtransport.Session) { for { - stream, err := session.AcceptStream(context.Background()) if err != nil { return } - go func(s *webtransport.Stream) { - + go func(s webtransport.Stream) { defer s.Close() buf := make([]byte, 1024) - n, _ := s.Read(buf) fmt.Println("Message:", string(buf[:n])) s.Write([]byte("Server: OK")) - - }(stream) - + }(*stream) } }