package main

import (
	"fmt"
	"log"
	"time"

	"github.com/zeromq/goczmq"
)

func main() {
	// 绑定到指定地址（可以是本地或远程 IP）
	endpoint := "tcp://0.0.0.0:5555" // 本机所有 IP 可访问
	sock, err := goczmq.NewPush(endpoint)
	if err != nil {
		log.Fatalf("Failed to create PUSH socket: %v", err)
	}
	defer sock.Destroy()

	fmt.Println("PUSH socket bound to", endpoint)

	// 定时发送消息
	for i := 0; i < 1000; i++ {
		msg := fmt.Sprintf("Hello %d", i)
		err := sock.SendFrame([]byte(msg), goczmq.FlagNone)
		if err != nil {
			log.Printf("Send error: %v", err)
		} else {
			fmt.Println("Sent:", msg)
		}
		time.Sleep(1 * time.Second)
	}
}
