You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
app.Get("/", func(ctx iris.Context) {
ctx.ServeFile("websockets.html", false) // second parameter: enable gzip?
})
setupWebsocket(app)
// x2
// http://localhost:8080
// http://localhost:8080
// write something, press submit, see the result.
app.Run(iris.Addr(":8080"))
}
func setupWebsocket(app *iris.Application) {
// create our echo websocket server
ws := websocket.New(websocket.Config{
// These are low-level optionally fields,
// user/client can't see those values.
ReadBufferSize: 1024,
WriteBufferSize: 1024,
// only javascript client-side code has the same rule,
// which you serve using the ws.ClientSource (see below).
EvtMessagePrefix: []byte("my-custom-prefix:"),
})
ws.OnConnection(handleConnection)
// register the server on an endpoint.
// see the inline javascript code in the websockets.html, this endpoint is used to connect to the server.
app.Get("/echo", ws.Handler())
// serve the javascript built'n client-side library,
// see websockets.html script tags, this path is used.
}
func handleConnection(c websocket.Connection) {
// Read events from browser
c.On("chat", func(msg string) {
// Print the message to the console, c.Context() is the iris's http context.
fmt.Printf("%s sent: %s\n", c.Context().RemoteAddr(), msg)
// Write message back to the client message owner with:
// c.Emit("chat", msg)
// Write message to all except this client with:
c.To(websocket.Broadcast).Emit("chat", msg)
})
}
`
log:
Now listening on: http://localhost:8080
Application started. Press CTRL+C to shut down.
WARNING: DATA RACE
Read at 0x00c0003fc038 by goroutine 20:
github.com/kataras/iris/websocket.(*connection).startPinger.func2()
/opt/gopath/src/github.com/kataras/iris/websocket/connection.go:346 +0x89
`package main
import (
"fmt"
)
func main() {
app := iris.New()
}
func setupWebsocket(app *iris.Application) {
// create our echo websocket server
ws := websocket.New(websocket.Config{
// These are low-level optionally fields,
// user/client can't see those values.
ReadBufferSize: 1024,
WriteBufferSize: 1024,
// only javascript client-side code has the same rule,
// which you serve using the ws.ClientSource (see below).
EvtMessagePrefix: []byte("my-custom-prefix:"),
})
ws.OnConnection(handleConnection)
}
func handleConnection(c websocket.Connection) {
// Read events from browser
c.On("chat", func(msg string) {
// Print the message to the console, c.Context() is the iris's http context.
fmt.Printf("%s sent: %s\n", c.Context().RemoteAddr(), msg)
// Write message back to the client message owner with:
// c.Emit("chat", msg)
// Write message to all except this client with:
c.To(websocket.Broadcast).Emit("chat", msg)
})
}
`
log:
Now listening on: http://localhost:8080
Application started. Press CTRL+C to shut down.
WARNING: DATA RACE
Read at 0x00c0003fc038 by goroutine 20:
github.com/kataras/iris/websocket.(*connection).startPinger.func2()
/opt/gopath/src/github.com/kataras/iris/websocket/connection.go:346 +0x89
Previous write at 0x00c0003fc038 by goroutine 18:
github.com/kataras/iris/websocket.(*Server).Disconnect()
/opt/gopath/src/github.com/kataras/iris/websocket/server.go:429 +0xc6
github.com/kataras/iris/websocket.(*connection).startReader.func2()
/opt/gopath/src/github.com/kataras/iris/websocket/connection.go:592 +0xc5
github.com/kataras/iris/websocket.(*connection).startReader()
/opt/gopath/src/github.com/kataras/iris/websocket/connection.go:413 +0x2e7
github.com/kataras/iris/websocket.(*connection).Wait()
/opt/gopath/src/github.com/kataras/iris/websocket/connection.go:581 +0x98
github.com/kataras/iris/websocket.(*Server).Handler.func1()
/opt/gopath/src/github.com/kataras/iris/websocket/server.go:108 +0x152
github.com/kataras/iris/context.Do()
/opt/gopath/src/github.com/kataras/iris/context/context.go:922 +0xa5
github.com/kataras/iris/context.(*context).Do()
/opt/gopath/src/github.com/kataras/iris/context/context.go:1094 +0x62
github.com/kataras/iris/core/router.(*routerHandler).HandleRequest()
/opt/gopath/src/github.com/kataras/iris/core/router/handler.go:227 +0x721
github.com/kataras/iris/core/router.(*Router).BuildRouter.func1()
/opt/gopath/src/github.com/kataras/iris/core/router/router.go:84 +0xc4
github.com/kataras/iris/core/router.(*Router).ServeHTTP()
/opt/gopath/src/github.com/kataras/iris/core/router/router.go:161 +0x69
net/http.serverHandler.ServeHTTP()
/opt/go/src/net/http/server.go:2774 +0xce
net/http.(*conn).serve()
/opt/go/src/net/http/server.go:1878 +0x811
Goroutine 20 (running) created at:
github.com/kataras/iris/websocket.(*connection).startPinger()
/opt/gopath/src/github.com/kataras/iris/websocket/connection.go:342 +0xdb
github.com/kataras/iris/websocket.(*connection).Wait()
/opt/gopath/src/github.com/kataras/iris/websocket/connection.go:578 +0x8a
github.com/kataras/iris/websocket.(*Server).Handler.func1()
/opt/gopath/src/github.com/kataras/iris/websocket/server.go:108 +0x152
github.com/kataras/iris/context.Do()
/opt/gopath/src/github.com/kataras/iris/context/context.go:922 +0xa5
github.com/kataras/iris/context.(*context).Do()
/opt/gopath/src/github.com/kataras/iris/context/context.go:1094 +0x62
github.com/kataras/iris/core/router.(*routerHandler).HandleRequest()
/opt/gopath/src/github.com/kataras/iris/core/router/handler.go:227 +0x721
github.com/kataras/iris/core/router.(*Router).BuildRouter.func1()
/opt/gopath/src/github.com/kataras/iris/core/router/router.go:84 +0xc4
github.com/kataras/iris/core/router.(*Router).ServeHTTP()
/opt/gopath/src/github.com/kataras/iris/core/router/router.go:161 +0x69
net/http.serverHandler.ServeHTTP()
/opt/go/src/net/http/server.go:2774 +0xce
net/http.(*conn).serve()
/opt/go/src/net/http/server.go:1878 +0x811
Goroutine 18 (finished) created at:
net/http.(*Server).Serve()
/opt/go/src/net/http/server.go:2884 +0x4c4
github.com/kataras/iris/core/host.(*Supervisor).Serve.func1()
/opt/gopath/src/github.com/kataras/iris/core/host/supervisor.go:220 +0x83
github.com/kataras/iris/core/host.(*Supervisor).supervise()
/opt/gopath/src/github.com/kataras/iris/core/host/supervisor.go:192 +0x4c
github.com/kataras/iris/core/host.(*Supervisor).Serve()
/opt/gopath/src/github.com/kataras/iris/core/host/supervisor.go:220 +0x78
github.com/kataras/iris/core/host.(*Supervisor).ListenAndServe()
/opt/gopath/src/github.com/kataras/iris/core/host/supervisor.go:232 +0x86
github.com/kataras/iris.Addr.func1()
/opt/gopath/src/github.com/kataras/iris/iris.go:666 +0x124
github.com/kataras/iris.(*Application).Run()
/opt/gopath/src/github.com/kataras/iris/iris.go:821 +0x16d
main.main()
/opt/gopath/src/stu/main.go:23 +0x144
The text was updated successfully, but these errors were encountered: