public override void Replicate() { Debug.Log("Enemy deployed: " + config.peerIPs[id] + ":" + config.peerPorts[id]); Thread.Sleep(100); Demultiplexer localInput = config.GetPlayer(0).GetInputDemultiplexer(); Link localLink = config.GetLink(0); while (!config.OnEscape()) { byte [] payload = localLink.Receive(link); if (payload != null) { Packet packet = new Packet(payload); PacketType type = packet.GetPacketType(); packet.Reset(); switch (type) { case PacketType.ACK: { localInput.Write(type, packet); break; } default: { // Se debe registrar y se debe generar un ACK de respuesta // en caso de que sea EVENT o FLOODING. input.Write(packet); break; } } } } }
/** * Recibe paquetes desde el servidor, y los agrega al demultiplexer de * entrada. */ protected void RequestHandler() { while (!config.OnExit()) { byte [] payload = local.Receive(server); if (payload != null) { Packet packet = new Packet(payload); input.Write(packet); } } }
/** * Aplica round-robin: por cada enlace de entrada (cada cliente conectado), lee * un paquete (si puede), y lo procesa o lo agrega al Demultiplexer. */ protected void RequestHandler() { IPEndPoint anyLink = new IPEndPoint(IPAddress.Any, 0); System.Random random = new System.Random(); while (!config.OnExit()) { byte [] payload = local.Receive(anyLink); if (payload != null && config.packetLossRatio <= random.NextDouble()) { Packet packet = new Packet(payload); lagSimulator.Write(packet, timestamp); } Packet futurePacket = lagSimulator.Read(timestamp); if (futurePacket != null) { input.Write(futurePacket); } } }