Created
May 16, 2013 23:18
-
-
Save fatih/5595875 to your computer and use it in GitHub Desktop.
Start in order go run zmq_device.go
go run zmq_server.go
go run zmq_client.go
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 main | |
| import ( | |
| "fmt" | |
| zmq "github.com/alecthomas/gozmq" | |
| ) | |
| func main() { | |
| context, _ := zmq.NewContext() | |
| socket, _ := context.NewSocket(zmq.REQ) | |
| defer context.Close() | |
| defer socket.Close() | |
| socket.Connect("tcp://127.0.0.1:7000") | |
| for i := 0; i < 10; i++ { | |
| msg := fmt.Sprintf("msg %d", i) | |
| socket.Send([]byte(msg), 0) | |
| println("Sending", msg) | |
| reply, _ := socket.Recv(0) | |
| println("Received ", string(reply)) | |
| } | |
| } |
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 main | |
| import ( | |
| "fmt" | |
| zmq "github.com/alecthomas/gozmq" | |
| ) | |
| func main() { | |
| fmt.Printf("zeromq device\n") | |
| context, _ := zmq.NewContext() | |
| defer context.Close() | |
| frontend, _ := context.NewSocket(zmq.ROUTER) | |
| defer frontend.Close() | |
| frontend.Connect("tcp://*:7000") | |
| backend, _ := context.NewSocket(zmq.DEALER) | |
| defer backend.Close() | |
| backend.Bind("tcp://*:7001") | |
| zmq.Device(zmq.QUEUE, frontend, backend) | |
| } |
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 main | |
| import ( | |
| "fmt" | |
| zmq "github.com/alecthomas/gozmq" | |
| ) | |
| func main() { | |
| fmt.Println("starting server") | |
| context, _ := zmq.NewContext() | |
| socket, _ := context.NewSocket(zmq.REP) | |
| defer context.Close() | |
| defer socket.Close() | |
| socket.Bind("tcp://127.0.0.1:7001") | |
| // Listen to messages | |
| for { | |
| msg, err := socket.Recv(0) | |
| if err != nil { | |
| fmt.Println(err) | |
| } | |
| println("Got", string(msg)) | |
| socket.Send(msg, 0) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment