Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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