Skip to content

Commit

Permalink
use the same connection structure for both client and server-side con…
Browse files Browse the repository at this point in the history
…nections interfaces, the 'Connection' interface could be changed to 'ServerConn' but this would produce breaking naming change to the iris users, so keep it as it's.
  • Loading branch information
kataras committed Feb 10, 2019
1 parent 90784f3 commit edaf461
Show file tree
Hide file tree
Showing 5 changed files with 258 additions and 296 deletions.
12 changes: 6 additions & 6 deletions _examples/websocket/go-client/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,21 @@ $ go run main.go
>> hi!
*/
func main() {
conn, err := websocket.Dial(url, websocket.DefaultEvtMessageKey)
c, err := websocket.Dial(url, websocket.ConnectionConfig{})
if err != nil {
panic(err)
}

conn.OnError(func(err error) {
c.OnError(func(err error) {
fmt.Printf("error: %v", err)
})

conn.OnDisconnect(func() {
fmt.Println("Server was force-closed[see ../server/main.go#L19] this connection after 20 seconds, therefore I am disconnected.")
c.OnDisconnect(func() {
fmt.Println("Server was force-closed[see ../server/main.go#L17] this connection after 20 seconds, therefore I am disconnected.")
os.Exit(0)
})

conn.On("chat", func(message string) {
c.On("chat", func(message string) {
fmt.Printf("\n%s\n", message)
})

Expand All @@ -51,7 +51,7 @@ func main() {
break
}

conn.Emit("chat", msgToSend)
c.Emit("chat", msgToSend)
}

fmt.Println("Terminated.")
Expand Down
4 changes: 2 additions & 2 deletions _examples/websocket/go-client/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
func main() {
app := iris.New()
ws := websocket.New(websocket.Config{})
app.Get("/socket", ws.Handler())

ws.OnConnection(func(c websocket.Connection) {
go func() {
<-time.After(20 * time.Second)
Expand All @@ -28,5 +26,7 @@ func main() {
})
})

app.Get("/socket", ws.Handler())

app.Run(iris.Addr(":8080"))
}
214 changes: 0 additions & 214 deletions websocket/client.go

This file was deleted.

Loading

0 comments on commit edaf461

Please sign in to comment.