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.

57 lines
1.2 KiB

8 years ago
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/tmlibs/common"
  9. "github.com/tendermint/tendermint/rpc/client"
  10. "github.com/tendermint/tendermint/rpc/types"
  11. "github.com/tendermint/go-wire"
  12. _ "github.com/tendermint/tendermint/rpc/tendermint/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",
  36. "broadcast_tx",
  37. map[string]interface{}{"tx": buf[:8]})
  38. reqBytes := wire.JSONBytes(request)
  39. //fmt.Println("!!", string(reqBytes))
  40. fmt.Print(".")
  41. err := ws.WriteMessage(websocket.TextMessage, reqBytes)
  42. if err != nil {
  43. Exit(err.Error())
  44. }
  45. if i%1000 == 0 {
  46. fmt.Println(i)
  47. }
  48. time.Sleep(time.Microsecond * 1000)
  49. }
  50. ws.Stop()
  51. }