本文整理汇总了Golang中github.com/kildevaeld/projects/Godeps/_workspace/src/github.com/gdamore/mangos.Socket.Dial方法的典型用法代码示例。如果您正苦于以下问题:Golang Socket.Dial方法的具体用法?Golang Socket.Dial怎么用?Golang Socket.Dial使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/kildevaeld/projects/Godeps/_workspace/src/github.com/gdamore/mangos.Socket
的用法示例。
在下文中一共展示了Socket.Dial方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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())
}
}
}
示例2: 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))
}
}
示例3: node1
func node1(url string) {
var sock mangos.Socket
var err error
if sock, err = pair.NewSocket(); err != nil {
die("can't get new pair socket: %s", err.Error())
}
sock.AddTransport(ipc.NewTransport())
sock.AddTransport(tcp.NewTransport())
if err = sock.Dial(url); err != nil {
die("can't dial on pair socket: %s", err.Error())
}
sendRecv(sock, "node1")
}
示例4: node1
func node1(url string, msg string) {
var sock mangos.Socket
var err error
if sock, err = push.NewSocket(); err != nil {
die("can't get new push socket: %s", err.Error())
}
sock.AddTransport(ipc.NewTransport())
sock.AddTransport(tcp.NewTransport())
if err = sock.Dial(url); err != nil {
die("can't dial on push socket: %s", err.Error())
}
fmt.Printf("NODE1: SENDING \"%s\"\n", msg)
if err = sock.Send([]byte(msg)); err != nil {
die("can't send message on push socket: %s", err.Error())
}
sock.Close()
}
示例5: node
func node(args []string) {
var sock mangos.Socket
var err error
var msg []byte
var x int
if sock, err = bus.NewSocket(); err != nil {
die("bus.NewSocket: %s", err)
}
sock.AddTransport(ipc.NewTransport())
sock.AddTransport(tcp.NewTransport())
if err = sock.Listen(args[2]); err != nil {
die("sock.Listen: %s", err.Error())
}
// wait for everyone to start listening
time.Sleep(time.Second)
for x = 3; x < len(args); x++ {
if err = sock.Dial(args[x]); err != nil {
die("socket.Dial: %s", err.Error())
}
}
// wait for everyone to join
time.Sleep(time.Second)
fmt.Printf("%s: SENDING '%s' ONTO BUS\n", args[1], args[1])
if err = sock.Send([]byte(args[1])); err != nil {
die("sock.Send: %s", err.Error())
}
for {
if msg, err = sock.Recv(); err != nil {
die("sock.Recv: %s", err.Error())
}
fmt.Printf("%s: RECEIVED \"%s\" FROM BUS\n", args[1],
string(msg))
}
}
示例6: clientWorker
func clientWorker(url string, id int) {
var sock mangos.Socket
var m *mangos.Message
var err error
if sock, err = req.NewSocket(); err != nil {
die("can't get new req socket: %s", err.Error())
}
// Leave this in Cooked mode!
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())
}
// send an empty messsage
m = mangos.NewMessage(1)
if err = sock.SendMsg(m); err != nil {
die("can't send request: %s", err.Error())
}
if m, err = sock.RecvMsg(); err != nil {
die("can't recv reply: %s", err.Error())
}
sock.Close()
if len(m.Body) != 4 {
die("bad response len: %d", len(m.Body))
}
worker := binary.BigEndian.Uint32(m.Body[0:])
L.Lock()
fmt.Printf("Client: %4d Server: %4d\n", id, worker)
L.Unlock()
}
示例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()
}