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.

56 lines
1.2 KiB

  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("ws://127.0.0.1:46657/websocket")
  16. // ws := rpcclient.NewWSClient("ws://104.236.69.128:46657/websocket")
  17. _, err := ws.Start()
  18. if err != nil {
  19. Exit(err.Error())
  20. }
  21. // Read a bunch of responses
  22. go func() {
  23. for {
  24. _, ok := <-ws.ResultsCh
  25. if !ok {
  26. break
  27. }
  28. //fmt.Println("Received response", string(wire.JSONBytes(res)))
  29. }
  30. }()
  31. // Make a bunch of requests
  32. buf := make([]byte, 32)
  33. for i := 0; ; i++ {
  34. binary.BigEndian.PutUint64(buf, uint64(i))
  35. //txBytes := hex.EncodeToString(buf[:n])
  36. request := rpctypes.NewRPCRequest("fakeid", "broadcast_tx", Arr(buf[:8]))
  37. reqBytes := wire.JSONBytes(request)
  38. //fmt.Println("!!", string(reqBytes))
  39. fmt.Print(".")
  40. err := ws.WriteMessage(websocket.TextMessage, reqBytes)
  41. if err != nil {
  42. Exit(err.Error())
  43. }
  44. if i%1000 == 0 {
  45. fmt.Println(i)
  46. }
  47. time.Sleep(time.Microsecond * 1000)
  48. }
  49. ws.Stop()
  50. }