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.

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