using the following code ,

package main

import (

type Message struct {
Id      int         `json:"id"`
Jsonrpc string      `json:"jsonrpc"`
Method  string      `json:"method"`
Params  interface{} `json:"params"`

func main() {
// create a new WebSocket connection to the Polkadot node
endpoint := fmt.Sprintf("ws://%s:%d", "localhost", 9944)
conn, _, err := websocket.DefaultDialer.Dial(endpoint, nil)
if err != nil {
    log.Fatal("dial:", err)
defer conn.Close()

// subscribe to new block headers
message := Message{
    Id:      1,
    Jsonrpc: "2.0",
    Method:  "system_health",
    Params:  []interface{}{},
err = conn.WriteJSON(message)
if err != nil {
    log.Fatal("write:", err)

// listen for new peers
for {
    _, message, err := conn.ReadMessage()
    if err != nil {
        log.Fatal("read:", err)
    fmt.Printf("New message: %s\n", message)
    // Do something with the new message

i get this response only once


and the the code blocks here : conn.ReadMessage()

however i expected it will stream the changes every time the peers count changes or isSyncing changes for example


and so one.

am i missing something here ?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.