Created
May 15, 2015 14:31
-
-
Save taotetek/42f849455c0d3671d058 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package goczmq | |
import ( | |
"fmt" | |
) | |
func ExampleTraditionalRequestResponder() { | |
go func() { | |
responder := NewSock(Rep) | |
_, err := responder.Bind("inproc://traditional") | |
// "messages" are full (and potentially multi-part) atomic messages. | |
// goczmq represents them as a [][]byte | |
b, err := responder.RecvMessage() | |
if err != nil { | |
panic(err) | |
} | |
fmt.Printf("Received %s\n", string(b[0])) | |
response := []byte("World") | |
responder.SendMessage([][]byte{response}) | |
fmt.Printf("Sent %s\n", string(response)) | |
}() | |
requestor := NewSock(Req) | |
err := requestor.Connect("inproc://traditional") | |
request := []byte("Hello") | |
err = requestor.SendMessage([][]byte{request}) | |
if err != nil { | |
panic(err) | |
} | |
fmt.Printf("Sent %s\n", string(request)) | |
response, err := requestor.RecvMessage() | |
if err != nil { | |
panic(err) | |
} | |
fmt.Printf("Received %s", string(response[0])) | |
//Output: | |
// Sent Hello | |
// Received Hello | |
// Sent World | |
// Received World | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment