2015-09-24 01:29:30 +03:00
|
|
|
// Copyright 2015 The Gorilla WebSocket Authors. All rights reserved.
|
2015-09-24 01:23:26 +03:00
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2015-09-24 01:29:30 +03:00
|
|
|
// +build ignore
|
|
|
|
|
2015-09-24 01:23:26 +03:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"log"
|
|
|
|
"net/url"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/gorilla/websocket"
|
|
|
|
)
|
|
|
|
|
|
|
|
var addr = flag.String("addr", "localhost:8081", "http service address")
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
flag.Parse()
|
|
|
|
log.SetFlags(0)
|
|
|
|
|
|
|
|
u := url.URL{Scheme: "ws", Host: *addr, Path: "/"}
|
|
|
|
log.Printf("connecting to %s", u.String())
|
|
|
|
|
2015-10-19 01:41:02 +03:00
|
|
|
c, _, err := websocket.DefaultDialer.Dial(u.String(), nil)
|
2015-09-24 01:23:26 +03:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal("dial:", err)
|
|
|
|
}
|
|
|
|
defer c.Close()
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
defer c.Close()
|
|
|
|
for {
|
|
|
|
_, message, err := c.ReadMessage()
|
|
|
|
if err != nil {
|
|
|
|
log.Println("read:", err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
log.Printf("recv: %s", message)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
ticker := time.NewTicker(5 * time.Second)
|
|
|
|
defer ticker.Stop()
|
|
|
|
|
|
|
|
for t := range ticker.C {
|
|
|
|
err := c.WriteMessage(websocket.TextMessage, []byte(t.String()))
|
|
|
|
if err != nil {
|
|
|
|
log.Println("write:", err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|