go-zeromq / zmq4

[WIP] Pure-Go implementation of ZeroMQ-4
BSD 3-Clause "New" or "Revised" License
333 stars 56 forks source link

PUB/SUB UDP socket #152

Open beaquant opened 5 months ago

beaquant commented 5 months ago

hello, could you have any example for zmq with udp? when I use this code with udp, but not success. I want using multicast udp, here is server code v0.16.0

server

    // prepare the publisher
    pub := zmq4.NewPub(context.Background())
    defer pub.Close()
    err := pub.Listen(fmt.Sprintf("udp://224.0.0.55:%s", port))
    if err != nil {
        log.Fatalf("could not listen: %v", err)
    }

    time.Sleep(time.Second * 1)
    fmt.Println("start")
    msg := []byte(`hello there`)

    msgB := zmq4.NewMsgFrom(
        []byte("B"),
        msg,
    )
    start := time.Now()
    for i := 0; i < num; i++ {
        pub.Send(msgB)
    }

    elapsed := time.Since(start)
    fmt.Println("Elapsed:", elapsed)
    fmt.Println("pps:", float64(num)/elapsed.Seconds()/10000, "w")

client
...

the server will fail with message psenvpub: 2024/02/05 18:29:19 could not listen: zmq4: could not listen to "udp://224.0.0.55:5563": listen udp 224.0.0.55:5563: address 224.0.0.55:5563: unexpected address type it seam error posted from net package

zonque commented 2 months ago

Same issue here. The problem is that (trans netTransport) Listen() would need to use net.ListenUDP() rather than net.Listen() for UDP, but then the interface would have to be refactored because the returned net.UDPConn does not implement net.Listener.

@sbinet any idea?