Skip to content

pub sub err , when close the server the client get error and close  #109

@lhd000

Description

@lhd000

in the zmq the server or client close never cause another one close
but the the below happen
i do not key why
could not receive message : read tcp 127.0.0.1:57509->127.0.0.1:5563: wsarecv: An existing connection was forcibly closed by the remote host.

server

package main

import (
"context"
"log"
"time"

"github.com/go-zeromq/zmq4"

)

func main() {
log.SetPrefix("psenvpub: ")

// prepare the publisher
pub := zmq4.NewPub(context.Background())
defer pub.Close()

err := pub.Listen("tcp://*:5563")
if err != nil {
	log.Fatalf("could not listen: %v", err)
}

msgA := zmq4.NewMsgFrom(
	[]byte("A"),
	[]byte("We don't want to see this"),
)
msgB := zmq4.NewMsgFrom(
	[]byte("B"),
	[]byte("We would like to see this"),
)
for {
	//  Write two messages, each with an envelope and content
	err = pub.Send(msgA)
	if err != nil {
		log.Fatal(err)
	}
	err = pub.Send(msgB)
	if err != nil {
		log.Fatal(err)
	}
	time.Sleep(time.Second)
}

}

client

package main

import (
"context"
"log"

"github.com/go-zeromq/zmq4"

)

func main() {
log.SetPrefix("psenvsub: ")

//  Prepare our subscriber
sub := zmq4.NewSub(context.Background())
defer sub.Close()

err := sub.Dial("tcp://localhost:5563")
if err != nil {
	log.Fatalf("could not dial: %v", err)
}

err = sub.SetOption(zmq4.OptionSubscribe, "B")
if err != nil {
	log.Fatalf("could not subscribe: %v", err)
}

for {
	// Read envelope
	msg, err := sub.Recv()
	if err != nil {
		log.Println("could not receive message :", err)
	}
	log.Printf("[%s] %s\n", msg.Frames[0], msg.Frames[1])
}

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions