Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
lhd000 opened this issue Aug 25, 2021 · 1 comment
Open

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

lhd000 opened this issue Aug 25, 2021 · 1 comment
Labels
bug Something isn't working

Comments

@lhd000
Copy link

lhd000 commented Aug 25, 2021

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])
}

}

@lhd000
Copy link
Author

lhd000 commented Aug 25, 2021

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.

@sbinet sbinet added the bug Something isn't working label Aug 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants