websocket support
qknight opened this issue · comments
when using gocraft/web
one has to server websockets on a different port than the legacy http service.
i've added example code below, as one can see:
- ws server is on port 12345
- gocraft's router is hosted on port 8080
i want both to listen on 8080, how to do that?
main.go
func main() {
server := ws.NewServer("/websocket")
go server.Listen()
go http.ListenAndServe("localhost:12345", nil) // Start the WS server!
go inotifyWatchDir("output"); // FIXME hardcoded path
router := web.New(Context{}). // Create your router
Middleware(web.LoggerMiddleware). // Use some included middleware
Middleware(web.ShowErrorsMiddleware). // ...
//Middleware(web.StaticMiddleware("../output")).
Middleware(web.StaticMiddleware("output")). // FIXME hardcoded path
Middleware((*Context).SetHelloCount). // Your own middleware!
Get("/", (*Context).SayHello) // Add a route
http.ListenAndServe("localhost:8080", router) // Start the server!
}
example websocket implementation i'm using:
https://github.com/golang-samples/websocket/
gorilla websockets
as pointed out in #24 i would also consider using gorilla websockets but i do not have a clue how to use the Hijacker interface
.
@phea ideas?
@qknight - here's an example that should get you started:
https://github.com/mlctrez/gowebsocket
This is https://github.com/golang-samples/websocket/tree/master/websocket-chat/src modified for gocraft web.
@mlctrez this is awesome! thanks so much.