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

Thread safe channel interface example problem #281

Open
wozuo opened this issue Jul 27, 2020 · 0 comments
Open

Thread safe channel interface example problem #281

wozuo opened this issue Jul 27, 2020 · 0 comments

Comments

@wozuo
Copy link

wozuo commented Jul 27, 2020

Hi everyone, thanks for this great project. I'm testing out the examples right now and ran into some problems. When executing the "Thread safe channel interface" example from the readme everything runs just fine. I get the following expected output:

router created and bound
dealer created and connected
dealer sent 'Hello'
router received 'Hello' from '[0 128 0 65 167]'
router sent 'World'
dealer received 'World'

But when I try to separate the client from the server, the serve does not receive the messages from the client any longer. The modified code which does not seem to work, looks like this:

func main() {
	args := os.Args[1:]

	if len(args) != 1 {
		fmt.Println("Specify run mode (either client or server)")
		return
	}

	switch args[0] {
	case "client":
		fmt.Println("Starting client...")
		startClient()
	case "server":
		fmt.Println("Starting server...")
		startServer()
	default:
		fmt.Println("Specify run mode (either client or server) ")
	}
}

func startServer() {
	router := goczmq.NewRouterChanneler("tcp://*:5555")
	defer router.Destroy()

	for {
		fmt.Println("Receiving message...")
		request := <-router.RecvChan

		fmt.Printf("router received '%s' from '%v'", request[1], request[0])
	}
}

func startClient() {
	dealer := goczmq.NewDealerChanneler("tcp://127.0.0.1:5555")
	defer dealer.Destroy()

	dealer.SendChan <- [][]byte{[]byte("Hello")}
	fmt.Println("Client sent hello")
}

And the output I get on the server side is this:

Starting server...
Receiving message...

And then is just hangs there forever

And the output I get on the client side is this:

Starting client...
Client sent hello

after which the program quits

Does anybody know what the problem is here? Thanks a best regards
Marc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant