本文整理汇总了Golang中github.com/kildevaeld/projects/cmd/Godeps/_workspace/src/github.com/gdamore/mangos.Socket.Recv方法的典型用法代码示例。如果您正苦于以下问题:Golang Socket.Recv方法的具体用法?Golang Socket.Recv怎么用?Golang Socket.Recv使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/kildevaeld/projects/cmd/Godeps/_workspace/src/github.com/gdamore/mangos.Socket
的用法示例。
在下文中一共展示了Socket.Recv方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: client
func client(url string, name string) {
var sock mangos.Socket
var err error
var msg []byte
if sock, err = sub.NewSocket(); err != nil {
die("can't get new sub socket: %s", err.Error())
}
sock.AddTransport(ipc.NewTransport())
sock.AddTransport(tcp.NewTransport())
if err = sock.Dial(url); err != nil {
die("can't dial on sub socket: %s", err.Error())
}
// Empty byte array effectively subscribes to everything
err = sock.SetOption(mangos.OptionSubscribe, []byte(""))
if err != nil {
die("cannot subscribe: %s", err.Error())
}
for {
if msg, err = sock.Recv(); err != nil {
die("Cannot recv: %s", err.Error())
}
fmt.Printf("CLIENT(%s): RECEIVED %s\n", name, string(msg))
}
}
示例2: node0
func node0(url string) {
var sock mangos.Socket
var err error
var msg []byte
if sock, err = rep.NewSocket(); err != nil {
die("can't get new rep socket: %s", err)
}
sock.AddTransport(ipc.NewTransport())
sock.AddTransport(tcp.NewTransport())
if err = sock.Listen(url); err != nil {
die("can't listen on rep socket: %s", err.Error())
}
for {
// Could also use sock.RecvMsg to get header
msg, err = sock.Recv()
if string(msg) == "DATE" { // no need to terminate
fmt.Println("NODE0: RECEIVED DATE REQUEST")
d := date()
fmt.Printf("NODE0: SENDING DATE %s\n", d)
err = sock.Send([]byte(d))
if err != nil {
die("can't send reply: %s", err.Error())
}
}
}
}
示例3: client
func client(url string, name string) {
var sock mangos.Socket
var err error
var msg []byte
if sock, err = respondent.NewSocket(); err != nil {
die("can't get new respondent socket: %s", err.Error())
}
sock.AddTransport(ipc.NewTransport())
sock.AddTransport(tcp.NewTransport())
if err = sock.Dial(url); err != nil {
die("can't dial on respondent socket: %s", err.Error())
}
for {
if msg, err = sock.Recv(); err != nil {
die("Cannot recv: %s", err.Error())
}
fmt.Printf("CLIENT(%s): RECEIVED \"%s\" SURVEY REQUEST\n",
name, string(msg))
d := date()
fmt.Printf("CLIENT(%s): SENDING DATE SURVEY RESPONSE\n", name)
if err = sock.Send([]byte(d)); err != nil {
die("Cannot send: %s", err.Error())
}
}
}
示例4: server
func server(url string) {
var sock mangos.Socket
var err error
var msg []byte
if sock, err = surveyor.NewSocket(); err != nil {
die("can't get new surveyor socket: %s", err)
}
sock.AddTransport(ipc.NewTransport())
sock.AddTransport(tcp.NewTransport())
if err = sock.Listen(url); err != nil {
die("can't listen on surveyor socket: %s", err.Error())
}
err = sock.SetOption(mangos.OptionSurveyTime, time.Second*2)
if err != nil {
die("SetOption(): %s", err.Error())
}
for {
fmt.Println("SERVER: SENDING DATE SURVEY REQUEST")
if err = sock.Send([]byte("DATE")); err != nil {
die("Failed sending survey: %s", err.Error())
}
for {
if msg, err = sock.Recv(); err != nil {
break
}
fmt.Printf("SERVER: RECEIVED \"%s\" SURVEY RESPONSE\n",
string(msg))
}
}
}
示例5: recvName
func recvName(sock mangos.Socket, name string) {
var msg []byte
var err error
if msg, err = sock.Recv(); err == nil {
fmt.Printf("%s: RECEIVED: \"%s\"\n", name, string(msg))
}
}
示例6: node0
func node0(url string) {
var sock mangos.Socket
var err error
var msg []byte
if sock, err = pull.NewSocket(); err != nil {
die("can't get new pull socket: %s", err)
}
sock.AddTransport(ipc.NewTransport())
sock.AddTransport(tcp.NewTransport())
if err = sock.Listen(url); err != nil {
die("can't listen on pull socket: %s", err.Error())
}
for {
// Could also use sock.RecvMsg to get header
msg, err = sock.Recv()
fmt.Printf("NODE0: RECEIVED \"%s\"\n", msg)
}
}
示例7: node1
func node1(url string) {
var sock mangos.Socket
var err error
var msg []byte
if sock, err = req.NewSocket(); err != nil {
die("can't get new req socket: %s", err.Error())
}
sock.AddTransport(ipc.NewTransport())
sock.AddTransport(tcp.NewTransport())
if err = sock.Dial(url); err != nil {
die("can't dial on req socket: %s", err.Error())
}
fmt.Printf("NODE1: SENDING DATE REQUEST %s\n", "DATE")
if err = sock.Send([]byte("DATE")); err != nil {
die("can't send message on push socket: %s", err.Error())
}
if msg, err = sock.Recv(); err != nil {
die("can't receive date: %s", err.Error())
}
fmt.Printf("NODE1: RECEIVED DATE %s\n", string(msg))
sock.Close()
}