本文整理匯總了Golang中agent.Comm.Broadcast方法的典型用法代碼示例。如果您正苦於以下問題:Golang Comm.Broadcast方法的具體用法?Golang Comm.Broadcast怎麽用?Golang Comm.Broadcast使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類agent.Comm
的用法示例。
在下文中一共展示了Comm.Broadcast方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Turn
func (self *Configurable) Turn(comm agent.Comm) {
broadcasted := comm.Broadcast(23, []byte("hello_world"))
if self.LogBroadcast {
comm.Log("Broadcast success:", broadcasted)
}
comm.Move(self.XVelocity, self.YVelocity)
if self.LogMove {
// comm.Logf("Pos: %v (%t)", self.Position(), success)
}
if self.LogListen {
comm.Log("Heard:", string(comm.Listen(23)))
}
if self.LogCollect {
comm.Log("Collected: ", comm.Collect())
}
if self.LogLook {
comm.Log("Look: ", comm.Collect())
}
if self.LogPrevious {
comm.Log("Previous: ", comm.PrevResult())
}
if self.LogEnergy {
comm.Log("Energy:", comm.Energy())
}
return
}
示例2: send_message
func (self *SendMachine) send_message(comm agent.Comm) (sent, isack bool) {
find := func() (*DataGram, bool) {
for i := 0; i < self.sendq.Len(); i++ {
msg, ok := self.sendq.Dequeue()
if !ok {
break
}
if _, has := self.routes[msg.DestAddr]; !has {
self.sendq.Queue(msg)
} else {
return msg, true
}
}
return nil, false
}
msg, found := find()
if !found {
return false, false
}
self.sendq.QueueFront(msg)
next := self.routes[msg.DestAddr].NextAddr
var pkt *Packet
if msg.IsAck() {
pkt = NewPacket(Commands["ACK"], self.agent.Id(), next)
} else {
pkt = NewPacket(Commands["MESSAGE"], self.agent.Id(), next)
}
pkt.SetBody(msg.Bytes())
bytes := pkt.Bytes()
comm.Broadcast(self.freq, bytes)
if !msg.IsAck() {
self.last_checksum = msg.ComputeChecksum()
}
self.last = bytes
self.log("info", self.agent.Time(), "sent", pkt, msg)
return true, msg.IsAck()
}