We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
$ go version go version go1.13.4 darwin/amd64
I'm trying to switch from gorilla/websocket to this nice lib, but having some trouble,
the serverWithGin() version will always timeout.
serverWithGin()
any help would be appreciated!
package main import ( "context" "log" "net/http" "time" "github.com/gin-gonic/gin" "nhooyr.io/websocket" ) func main() { go serveWithGin() // go serve() go client() select {} } func serve() { http.HandleFunc("/ws", func(writer http.ResponseWriter, request *http.Request) { conn, err := websocket.Accept(writer, request, nil) if err != nil { log.Fatal(err) } ctx, cancel := context.WithTimeout(context.Background(), time.Minute) defer cancel() err = conn.Write(ctx, websocket.MessageText, []byte("hello")) if err != nil { log.Fatal(err) } }) log.Fatal(http.ListenAndServe(":8100", nil)) } func serveWithGin() { r := gin.Default() r.GET("/ws", func(c *gin.Context) { conn, err := websocket.Accept(c.Writer, c.Request, nil) if err != nil { log.Fatal(err) } ctx, cancel := context.WithTimeout(context.Background(), time.Minute) defer cancel() err = conn.Write(ctx, websocket.MessageText, []byte("hello")) if err != nil { log.Fatal(err) } }) r.Run(":8100") } func client() { ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) defer cancel() cli, _, err := websocket.Dial(ctx, "ws://localhost:8100/ws", nil) if err != nil { log.Fatal(err) } _, data, err := cli.Read(ctx) if err != nil { log.Fatal(err) } log.Printf("recv: %v\n", string(data)) }
The text was updated successfully, but these errors were encountered:
sorry, Just found #166
Sorry, something went wrong.
@master-g Should work now with gin-gonic btw.
No branches or pull requests
I'm trying to switch from gorilla/websocket to this nice lib, but having some trouble,
the
serverWithGin()
version will always timeout.any help would be appreciated!
The text was updated successfully, but these errors were encountered: