當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Comm.Listen方法代碼示例

本文整理匯總了Golang中agent.Comm.Listen方法的典型用法代碼示例。如果您正苦於以下問題:Golang Comm.Listen方法的具體用法?Golang Comm.Listen怎麽用?Golang Comm.Listen使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在agent.Comm的用法示例。


在下文中一共展示了Comm.Listen方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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
}
開發者ID:jmptrader,項目名稱:Tecellate,代碼行數:26,代碼來源:configurable.go

示例2: PerformListens

func (self *SendMachine) PerformListens(comm agent.Comm) *DataGram {
	switch self.state {
	case 1:
		return nil
	}
	pkt := MakePacket(comm.Listen(self.freq))
	if !pkt.ValidateChecksum() {
		return nil
	}
	ok, cmd, _ := pkt.Cmd()
	if !ok {
		return nil
	}
	switch cmd {
	case Commands["MESSAGE"]:
		myaddr := uint32(self.agent.Id())
		to := pkt.ToField()
		from := pkt.FromField()
		body := pkt.GetBody(PacketBodySize)
		self.qlog("heard", from, "sent to", to, "pkt", pkt, MakeDataGram(body))
		if to == myaddr {
			msg := MakeDataGram(body)
			if msg.ValidateChecksum() {
				ack := NewAckGram(msg.ComputeChecksum(), myaddr, from)
				self.sendq.QueueFront(ack)
				//                     ack_pkt := NewPacket(Commands["ACK"], myaddr, from)
				//                     ack_pkt.SetBody(ack.Bytes())
				//                     bytes := ack_pkt.Bytes()
				//                     comm.Broadcast(self.freq, bytes)
				if msg.DestAddr == myaddr {
					return msg
				}
				self.sendq.Queue(msg)
			}
		}
	}
	return nil
}
開發者ID:jmptrader,項目名稱:Tecellate,代碼行數:38,代碼來源:send_machine.go

示例3: confirm_acked

func (self *SendMachine) confirm_acked(comm agent.Comm) (confirm bool) {

	cur := comm.Listen(self.freq)
	if self.last.Eq(cur) {
		self.qlog("heard my own packet")
		self.heard_last = true
		return false
	}

	if self.heard_last == false {
		self.wait -= 1
		if self.wait == 0 {
			self.state = 0
			self.backoff = self.backoff * (pseudo_rand.Float64()*2 + 1)
			self.wait = uint32(self.backoff)
			self.qlog("didn't hear last waiting...", self.wait)
		}
		return false
	}

	self.ack_wait -= 1
	if self.ack_wait == 0 {
		self.ack_backoff = self.ack_backoff * (pseudo_rand.Float64()*2 + 1)
		self.ack_wait = uint32(self.ack_backoff)
		self.state = 0
		return false
	}

	pkt := MakePacket(cur)
	if !pkt.ValidateChecksum() {
		return false
	}
	ok, cmd, _ := pkt.Cmd()
	if !ok {
		return false
	}
	self.log("info", self.agent.Time(), "got possible ack pkt", pkt)
	switch cmd {
	case Commands["ACK"]:
		self.log("info", self.agent.Time(), "it is an ack")
		myaddr := self.agent.Id()
		to := pkt.ToField()
		body := pkt.GetBody(PacketBodySize)
		self.log("info", self.agent.Time(), "it is to me?", myaddr, to)
		if to == myaddr {
			msg := MakeDataGram(body)
			self.log("info", self.agent.Time(), "the datagram", msg)
			if msg.ValidateChecksum() {
				self.log("info", self.agent.Time(), "it validates")
				self.log("info", self.agent.Time(), "it dest", msg.DestAddr, "myaddr", myaddr)
				if msg.DestAddr == myaddr {
					self.log("info", self.agent.Time(), "it dest == myaddr")
					bytes := msg.Body()[0:4]
					self.log("info", self.agent.Time(), "bytes", bytes, "last", self.last_checksum)
					if self.last_checksum.Eq(bytes) {
						return true
					}
				}
			}
		}
	}
	return false
}
開發者ID:jmptrader,項目名稱:Tecellate,代碼行數:63,代碼來源:send_machine.go

示例4: confirm_last

func (self *SendMachine) confirm_last(comm agent.Comm) (confirm bool) {
	bytes := comm.Listen(self.freq)
	confirm = self.last.Eq(bytes)
	self.log("info", self.agent.Time(), "confirm_last", confirm)
	return
}
開發者ID:jmptrader,項目名稱:Tecellate,代碼行數:6,代碼來源:send_machine.go


注:本文中的agent.Comm.Listen方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。