Skip to content

Instantly share code, notes, and snippets.

@zorchenhimer
Created March 14, 2019 04:11
Show Gist options
  • Save zorchenhimer/1d7c28fa3257a76088863b848697aaa6 to your computer and use it in GitHub Desktop.
Save zorchenhimer/1d7c28fa3257a76088863b848697aaa6 to your computer and use it in GitHub Desktop.
package main
import (
"flag"
"fmt"
"strconv"
"time"
"github.com/gorilla/websocket"
)
func main() {
flag.Parse()
count, _ := strconv.Atoi(flag.Arg(0))
fmt.Println("count:", count-1)
for i := 0; i < 1; i++ {
go chatter(i)
}
for {}
}
func chatter(number int) {
ws, _, err := websocket.DefaultDialer.Dial("ws://localhost:8089/ws", nil)
if err != nil {
panic(err)
}
ws.WriteMessage(websocket.TextMessage, []byte(fmt.Sprintf("Chatter_%d", number)))
go func() {
for {
_, msg, err := ws.ReadMessage()
if err != nil {
panic(err)
}
fmt.Printf(fmt.Sprintf("R: %s\n", msg))
}
}()
count := int64(0)
for {
msg := fmt.Sprintf("S: %d", count)
ws.WriteMessage(websocket.TextMessage, []byte(msg))
fmt.Println(msg)
time.Sleep(time.Millisecond * 50)
count++
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment