本文整理汇总了Golang中github.com/pebbe/zmq4.Socket.SetZapDomain方法的典型用法代码示例。如果您正苦于以下问题:Golang Socket.SetZapDomain方法的具体用法?Golang Socket.SetZapDomain怎么用?Golang Socket.SetZapDomain使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/pebbe/zmq4.Socket
的用法示例。
在下文中一共展示了Socket.SetZapDomain方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestSecurityNull
//.........这里部分代码省略.........
reactor.AddSocket(handler, zmq.POLLIN, doHandler)
reactor.AddChannel(quit, 0, doQuit)
go func() {
reactor.Run(100 * time.Millisecond)
quit <- true
}()
defer func() {
quit <- true
<-quit
close(quit)
}()
// We bounce between a binding server and a connecting client
server, err = zmq.NewSocket(zmq.DEALER)
if err != nil {
t.Fatal("NewSocket:", err)
}
client, err = zmq.NewSocket(zmq.DEALER)
if err != nil {
t.Fatal("NewSocket:", err)
}
// We first test client/server with no ZAP domain
// Libzmq does not call our ZAP handler, the connect must succeed
err = server.Bind("tcp://127.0.0.1:9683")
if err != nil {
t.Fatal("server.Bind:", err)
}
err = client.Connect("tcp://127.0.0.1:9683")
if err != nil {
t.Fatal("client.Connect:", err)
}
msg, err := bounce(server, client)
if err != nil {
t.Error(msg, err)
}
server.Unbind("tcp://127.0.0.1:9683")
client.Disconnect("tcp://127.0.0.1:9683")
// Now define a ZAP domain for the server; this enables
// authentication. We're using the wrong domain so this test
// must fail.
err = server.SetZapDomain("WRONG")
if err != nil {
t.Fatal("server.SetZapDomain:", err)
}
err = server.Bind("tcp://127.0.0.1:9687")
if err != nil {
t.Fatal("server.Bind:", err)
}
err = client.Connect("tcp://127.0.0.1:9687")
if err != nil {
t.Fatal("client.Connect:", err)
}
err = client.SetRcvtimeo(time.Second)
if err != nil {
t.Fatal("client.SetRcvtimeo:", err)
}
err = server.SetRcvtimeo(time.Second)
if err != nil {
t.Fatal("server.SetRcvtimeo:", err)
}
_, err = bounce(server, client)
if err == nil {
t.Error("Expected failure, got success")
}
server.Unbind("tcp://127.0.0.1:9687")
client.Disconnect("tcp://127.0.0.1:9687")
// Now use the right domain, the test must pass
err = server.SetZapDomain("TEST")
if err != nil {
t.Fatal("server.SetZapDomain:", err)
}
err = server.Bind("tcp://127.0.0.1:9688")
if err != nil {
t.Fatal("server.Bind:", err)
}
err = client.Connect("tcp://127.0.0.1:9688")
if err != nil {
t.Fatal("client.Connect:", err)
}
msg, err = bounce(server, client)
if err != nil {
t.Error(msg, err)
}
server.Unbind("tcp://127.0.0.1:9688")
client.Disconnect("tcp://127.0.0.1:9688")
err = client.Close()
client = nil
if err != nil {
t.Error("client.Close:", err)
}
err = server.Close()
server = nil
if err != nil {
t.Error("server.Close:", err)
}
}