s/c/conn/

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2019-05-11 20:14:37 -07:00
parent 36a23911a8
commit cffb4344d0
2 changed files with 11 additions and 6 deletions

5
example-gorilla/Makefile Normal file
View File

@ -0,0 +1,5 @@
server:
go run server.go
client:
go run client.go

View File

@ -50,16 +50,16 @@ func main() {
u := url.URL{Scheme: "ws", Host: *addr, Path: "/echo"}
log.Printf("connecting to %s", u.String())
c, _, err := websocket.DefaultDialer.Dial(u.String(), nil)
conn, _, err := websocket.DefaultDialer.Dial(u.String(), nil)
if err != nil {
log.Fatal("dial:", err)
}
defer c.Close()
defer conn.Close()
done := make(chan struct{})
// handle inbound messages on the channel
go readConn(done, c)
go readConn(done, conn)
ticker := time.NewTicker(time.Second)
defer ticker.Stop()
@ -69,7 +69,7 @@ func main() {
case <-done:
return
case t := <-ticker.C:
err := c.WriteMessage(websocket.TextMessage, []byte(t.String()))
err := conn.WriteMessage(websocket.TextMessage, []byte(t.String()))
if err != nil {
log.Println("write:", err)
return
@ -78,7 +78,7 @@ func main() {
msg := pb.CreateSampleEvent()
msg.Name = "test echo over gorilla websocket"
data, _ := proto.Marshal(msg)
err2 := c.WriteMessage(websocket.BinaryMessage, data)
err2 := conn.WriteMessage(websocket.BinaryMessage, data)
if err2 != nil {
log.Println("write:", err2)
return
@ -88,7 +88,7 @@ func main() {
// Cleanly close the connection by sending a close message and then
// waiting (with timeout) for the server to close the connection.
err := c.WriteMessage(websocket.CloseMessage, websocket.FormatCloseMessage(websocket.CloseNormalClosure, ""))
err := conn.WriteMessage(websocket.CloseMessage, websocket.FormatCloseMessage(websocket.CloseNormalClosure, ""))
if err != nil {
log.Println("write close:", err)
return