本文整理汇总了Golang中websocket.Handler函数的典型用法代码示例。如果您正苦于以下问题:Golang Handler函数的具体用法?Golang Handler怎么用?Golang Handler使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Handler函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
http.Handle("/echo", websocket.Handler(EchoServer))
http.Handle("/lobby", websocket.Handler(LobbyServer))
http.Handle("/", http.FileServer(http.Dir("/tmp")))
fmt.Println("Listening on:", listenAddress)
if err := http.ListenAndServe(listenAddress, nil); err != nil {
panic("ListenAndServe: " + err.String())
}
}
开发者ID:uglybrd,项目名称:GoGameHTML5,代码行数:9,代码来源:server.go
示例2: ExampleHandler
// This example demonstrates a trivial echo server.
func ExampleHandler() {
http.Handle("/echo", websocket.Handler(EchoServer))
err := http.ListenAndServe(":12345", nil)
if err != nil {
panic("ListenAndServe: " + err.Error())
}
}
开发者ID:npe9,项目名称:minimega,代码行数:8,代码来源:examplehandler_test.go
示例3: main
func main() {
flag.Parse()
go hub()
var err error
session, err = mgo.Mongo("localhost")
if err != nil {
panic("main > Mongo: " + err.Error())
}
defer session.Close()
pfx := "/static/"
h := http.StripPrefix(pfx, http.FileServer(http.Dir("../static/")))
http.Handle(pfx, h) // It is absurd I had to work that hard to serve static files. Let's shove them on AWS or something and forget about it
http.HandleFunc("/tickle", doTickle)
http.HandleFunc("/keys", viewKeys)
http.HandleFunc("/keys/add", addKey)
http.HandleFunc("/keys/check", checkKey)
http.HandleFunc("/links/send", sendLink)
http.HandleFunc("/register", registerHandler)
http.HandleFunc("/openid/callback", openID)
http.HandleFunc("/openid/callback/chrome", openID)
http.HandleFunc("/users/validate", validateUser)
http.HandleFunc("/logout", doLogout)
http.HandleFunc("/login", doLogin)
http.HandleFunc("/links/", linksList)
http.HandleFunc("/", rootHandler)
http.Handle("/ws", websocket.Handler(wsHandler))
if err := http.ListenAndServe(*addr, nil); err != nil {
log.Fatal("ListenAndServe:", err)
}
}
开发者ID:klinster,项目名称:Bessie,代码行数:31,代码来源:twocloud.go
示例4: accept
// Accepts a http connection & request pair. It upgrades the connection and calls
// proceed if succesfull.
//
// TODO: Remove the ugly channels and timeouts. They should not be needed!
func (s *websocketSocket) accept(w http.ResponseWriter, req *http.Request, proceed func()) (err os.Error) {
if s.connected {
return ErrConnected
}
f := func(ws *websocket.Conn) {
err = nil
ws.SetReadTimeout(s.t.rtimeout)
ws.SetWriteTimeout(s.t.wtimeout)
s.connected = true
s.ws = ws
s.close = make(chan byte)
defer close(s.close)
proceed()
// must block until closed
<-s.close
}
err = errWebsocketHandshake
if _, ok := req.Header["Sec-Websocket-Key1"]; ok {
websocket.Handler(f).ServeHTTP(w, req)
} else {
websocket.Draft75Handler(f).ServeHTTP(w, req)
}
return
}
开发者ID:andradeandrey,项目名称:go-socket.io,代码行数:33,代码来源:transport_websocket.go
示例5: HandleChans
// We export a single function, which creates a page controlled by a
// single websocket. It's quite primitive, and yet quite easy to use!
func HandleChans(url string, handler func(evts <-chan string, pages chan<- string, done <-chan os.Error)) {
myh := func(ws *websocket.Conn) {
evts := make(chan string)
pages := make(chan string)
done := make(chan os.Error)
go handler(evts, pages, done)
go func() {
r := bufio.NewReader(ws)
for {
x, err := r.ReadString('\n')
if err == nil {
evts <- x[:len(x)-1]
} else {
done <- os.NewError("Error from r.ReadString: " + err.String())
return
}
}
}()
for {
x := <-pages
_, err := fmt.Fprintln(ws, x)
if err != nil {
done <- os.NewError("Error in fmt.Fprintln: " + err.String())
return
}
}
}
http.Handle(path.Join(url, "socket"), websocket.Handler(myh))
skeleton := func(c http.ResponseWriter, req *http.Request) {
c.SetHeader("Content-Type", "text/html")
fmt.Fprintln(c, skeletonpage(req))
}
http.HandleFunc(url, skeleton)
}
开发者ID:droundy,项目名称:abridge,代码行数:37,代码来源:interactive.go
示例6: main
func main() {
http.Handle("/echo", websocket.Handler(EchoServer))
err := http.ListenAndServe(":12345", nil)
if err != nil {
panic("ListenAndServe: " + err.String())
}
}
开发者ID:taysom,项目名称:tau,代码行数:7,代码来源:socket.go
示例7: Listen
func (this *WebSocketListener) Listen() {
http.Serve(this.listener, websocket.Handler(func(connection *websocket.Conn) {
// The HTTP package creates the goroutine itself. No need for us to do it.
// Set the RemoteAddr here because of Go Bug #1636
this.ConnectionHandler(this.ircd, connection, connection.Request.RemoteAddr)
}))
}
开发者ID:ahf,项目名称:ircd-novo,代码行数:7,代码来源:listeners.go
示例8: evServer
func evServer(w http.ResponseWriter, r *http.Request) {
wevs := make(chan store.Event)
path := r.URL.Path[len("/$events"):]
glob, err := store.CompileGlob(path + "**")
if err != nil {
w.WriteHeader(400)
return
}
rev, _ := Store.Snap()
go func() {
walk(path, Store, wevs)
for {
ch, err := Store.Wait(glob, rev+1)
if err != nil {
break
}
ev, ok := <-ch
if !ok {
break
}
wevs <- ev
rev = ev.Rev
}
close(wevs)
}()
websocket.Handler(func(ws *websocket.Conn) {
send(ws, path, wevs)
ws.Close()
}).ServeHTTP(w, r)
}
开发者ID:Br3nda,项目名称:doozerd,代码行数:34,代码来源:web.go
示例9: HandleSeparate
// We export a single function, which creates a page controlled by a
// single websocket. It's quite primitive, and yet quite easy to use!
func HandleSeparate(url string, hh func() Handler) {
myh := func(ws *websocket.Conn) {
h := hh()
h.AddSend(func(p string) { fmt.Fprintln(ws, p) })
fmt.Fprintln(ws, "start")
r := bufio.NewReader(ws)
for {
x, err := r.ReadString('\n')
if err == nil {
h.Handle(x[:len(x)-1])
} else {
h.Done(os.NewError("Error from r.ReadString: " + err.String()))
return
}
}
}
http.Handle(path.Join(url, "socket"), websocket.Handler(myh))
skeleton := func(c http.ResponseWriter, req *http.Request) {
c.Header().Set("Content-Type", "text/html")
fmt.Fprintln(c, skeletonpage(req))
}
http.HandleFunc(url, skeleton)
}
开发者ID:mattn,项目名称:gui,代码行数:27,代码来源:websocket.go
示例10: Start
func Start(ch *chan int, st *State.State) {
world = *ch
state = st
go http.ListenAndServe(":25560", http.HandlerFunc(httpServe))
go http.ListenAndServe(":25561", websocket.Handler(wssServe))
// os.ForkExec("http://localhost:25560/index.oc", []string{}, []string{}, "", []*os.File{})
}
开发者ID:CasualSuperman,项目名称:Ourcraft,代码行数:7,代码来源:gui.go
示例11: makeWsConnHandler
func makeWsConnHandler(core *WsHttpCore) http.Handler {
return websocket.Handler(func(c *websocket.Conn) {
id := core.RegisterConn(c)
log.Println("send connid", id)
c.Write([]byte(id))
// chanWriter := core.MakeChanWriter(id)
jsChan := core.MakeJsonChan(id)
for {
var data WsHttpMsg
err := websocket.JSON.Receive(c, &data)
if err != nil {
log.Println("Error reading, socket closed")
break
}
log.Println("recvd.", id, data)
jsChan <- &data
}
// _,err := io.Copy(chanWriter,c)
// if err != nil {
// log.Println("wshttp.conn.error",id,err)
// }
// chanWriter.Close()
core.RemoveConn(id)
})
}
开发者ID:cheng81,项目名称:goexp-wshttp,代码行数:26,代码来源:wshttp.go
示例12: main
func main() {
flag.Parse()
go hub()
http.Handle("/broadcast", websocket.Handler(clientHandler))
if err := http.ListenAndServe(*addr, nil); err != nil {
log.Exit("ListenAndServe:", err)
}
}
开发者ID:blindsey,项目名称:wsbench,代码行数:8,代码来源:broadcast_server.go
示例13: main
func main() {
http.Handle("/", websocket.Handler(Echo))
http.Handle("/send", http.HandlerFunc(myHandler))
if err := http.ListenAndServe("localhost:1234", nil); err != nil {
log.Fatal("ListenAndServe:", err)
}
}
开发者ID:likesea,项目名称:GoLearn,代码行数:8,代码来源:webSocketServer.go
示例14: webSocketProtocolSwitch
func webSocketProtocolSwitch(c http.ResponseWriter, req *http.Request) {
// Handle old and new versions of protocol.
if _, found := req.Header["Sec-Websocket-Key1"]; found {
websocket.Handler(clientHandler).ServeHTTP(c, req)
} else {
websocket.Draft75Handler(clientHandler).ServeHTTP(c, req)
}
}
开发者ID:ngd,项目名称:chrome-bench,代码行数:8,代码来源:flicker.go
示例15: main
func main() {
http.HandleFunc("/", NotFoundServer)
http.HandleFunc("/test", HtmlResponseServer)
http.Handle("/ws", websocket.Handler(WebSocketServer))
err := http.ListenAndServe(":8888", nil)
if err != nil {
log.Fatal("ListenAndServe: ", err)
}
}
开发者ID:Saikees,项目名称:practice,代码行数:9,代码来源:websocket.go
示例16: main
func main() {
log.Println("Starting Server...")
http.Handle("/ws", websocket.Handler(handler))
err := http.ListenAndServe(":8080", nil)
if err != nil {
panic("ListenAndServe: " + err.String())
}
}
开发者ID:svenlange,项目名称:websocket,代码行数:11,代码来源:server.go
示例17: main
func main() {
log.Println("Starting Server...")
http.Handle("/echo", websocket.Handler(echoServer))
// http.Handle("/ws", websocket.Handler(handler));
// http.HandleFunc("/", handlerSimple);
err := http.ListenAndServe(":8080", nil)
if err != nil {
panic("ListenAndServe: " + err.String())
}
}
开发者ID:taysom,项目名称:tau,代码行数:12,代码来源:server.go
示例18: newWebsocketHandler
// newWebsocketHandler creates a new handler for websocket connections.
//
// vhost - The related vhost.
// endpoint - The parent websocket endpoint.
//
// Returns new handler.
func newWebsocketHandler(vhost *Vhost, endpoint *WebsocketEndpoint) (h *websocketHandler) {
h = &websocketHandler{
vhost: vhost,
alive: true,
endpoint: endpoint,
conns: make(map[string]*WebsocketConnection),
}
h.handler = websocket.Handler(func(ws *websocket.Conn) {
h.handle(ws)
})
return h
}
开发者ID:pote,项目名称:webrocket,代码行数:18,代码来源:websocket_handler.go
示例19: main
func main() {
fmt.Println("begin")
http.Handle("/", http.FileServer(http.Dir("."))) // <-- note this line
http.Handle("/socket", websocket.Handler(Echo))
if err := http.ListenAndServe(":1234", nil); err != nil {
log.Fatal("ListenAndServe:", err)
}
fmt.Println("end")
}
开发者ID:heweitykc,项目名称:ball,代码行数:12,代码来源:main.go
示例20: main
func main() {
data, err := ioutil.ReadFile("log")
str := string(data)
lines = strings.Split(str, "\n")
http.Handle("/", websocket.Handler(Handle))
fmt.Println("Handling.")
err = http.ListenAndServe(":3654", nil)
if err != nil {
fmt.Println("ListenAndServe failed.")
fmt.Println(err)
}
}
开发者ID:CasualSuperman,项目名称:GoIRC,代码行数:13,代码来源:goirc.go
注:本文中的websocket.Handler函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论