-
Notifications
You must be signed in to change notification settings - Fork 157
New issue
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
Good project,Thanks!!! Use low memory and very fast!!! #72
Comments
Thank you very much! 😄 |
@lesismal I want to chime in to thank you for "spamming" the gobwas/1mil repos with comments. |
You are welcome and thank you for your feedback! The problem of gobwas/ws+netpoll can't be solved until they implement async-streaming-parser for http and websocket. My repo does not have that problem, and passes the Autobahn Test: You could try websocket with nbio like this: package main
import (
"context"
"fmt"
"net/http"
"os"
"os/signal"
"time"
"github.com/lesismal/nbio/nbhttp"
"github.com/lesismal/nbio/nbhttp/websocket"
)
func newUpgrader() *websocket.Upgrader {
u := websocket.NewUpgrader()
u.OnMessage(func(c *websocket.Conn, messageType websocket.MessageType, data []byte) {
// echo
c.WriteMessage(messageType, data)
})
u.OnClose(func(c *websocket.Conn, err error) {
fmt.Println("OnClose:", c.RemoteAddr().String(), err)
})
return u
}
func onWebsocket(w http.ResponseWriter, r *http.Request) {
upgrader := newUpgrader()
conn, err := upgrader.Upgrade(w, r, nil)
if err != nil {
panic(err)
}
wsConn := conn.(*websocket.Conn)
wsConn.SetReadDeadline(time.Time{})
fmt.Println("OnOpen:", wsConn.RemoteAddr().String())
}
func main() {
mux := &http.ServeMux{}
mux.HandleFunc("/ws", onWebsocket)
svr := nbhttp.NewServer(nbhttp.Config{
Network: "tcp",
Addrs: []string{"localhost:8080"},
}, mux, nil)
err := svr.Start()
if err != nil {
fmt.Printf("nbio.Start failed: %v\n", err)
return
}
interrupt := make(chan os.Signal, 1)
signal.Notify(interrupt, os.Interrupt)
<-interrupt
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel()
svr.Shutdown(ctx)
} For more examples, refer to README and: |
@lesismal thanks a lot again, I will proceed to try that. |
Thank you for your feedback, I'll close this issue. |
No description provided.
The text was updated successfully, but these errors were encountered: