You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.2 KiB

9 years ago
  1. package main
  2. import (
  3. "encoding/binary"
  4. "time"
  5. //"encoding/hex"
  6. "fmt"
  7. "github.com/gorilla/websocket"
  8. . "github.com/tendermint/go-common"
  9. "github.com/tendermint/go-rpc/client"
  10. "github.com/tendermint/go-rpc/types"
  11. "github.com/tendermint/go-wire"
  12. _ "github.com/tendermint/tendermint/rpc/core/types" // Register RPCResponse > Result types
  13. )
  14. func main() {
  15. ws := rpcclient.NewWSClient("127.0.0.1:46657", "/websocket")
  16. _, err := ws.Start()
  17. if err != nil {
  18. Exit(err.Error())
  19. }
  20. // Read a bunch of responses
  21. go func() {
  22. for {
  23. _, ok := <-ws.ResultsCh
  24. if !ok {
  25. break
  26. }
  27. //fmt.Println("Received response", string(wire.JSONBytes(res)))
  28. }
  29. }()
  30. // Make a bunch of requests
  31. buf := make([]byte, 32)
  32. for i := 0; ; i++ {
  33. binary.BigEndian.PutUint64(buf, uint64(i))
  34. //txBytes := hex.EncodeToString(buf[:n])
  35. request := rpctypes.NewRPCRequest("fakeid", "broadcast_tx", Arr(buf[:8]))
  36. reqBytes := wire.JSONBytes(request)
  37. //fmt.Println("!!", string(reqBytes))
  38. fmt.Print(".")
  39. err := ws.WriteMessage(websocket.TextMessage, reqBytes)
  40. if err != nil {
  41. Exit(err.Error())
  42. }
  43. if i%1000 == 0 {
  44. fmt.Println(i)
  45. }
  46. time.Sleep(time.Microsecond * 1000)
  47. }
  48. ws.Stop()
  49. }