Called when new UDP packet received.
@param  string $pct
@return void
341030
public function onUdpPacket($pct)
    {
        if (mb_orig_strlen($pct) < 10) {
            return;
        }
        $orig = $pct;
        $this->response = [];
        Binary::getWord($pct); // ID
        $bitmap = Binary::getBitmap(Binary::getByte($pct)) . Binary::getBitmap(Binary::getByte($pct));
        //$qr = (int) $bitmap[0];
        $opcode = bindec(substr($bitmap, 1, 4));
        //$aa = (int) $bitmap[5];
        //$tc = (int) $bitmap[6];
        //$rd = (int) $bitmap[7];
        //$ra = (int) $bitmap[8];
        //$z = bindec(substr($bitmap, 9, 3));
        $rcode = bindec(mb_orig_substr($bitmap, 12));
        $this->response['status'] = [
            'rcode' => $rcode,
            'msg' => $this->getMessageByRcode($rcode)
        ];
        $qdcount = Binary::getWord($pct);
        $ancount = Binary::getWord($pct);
        $nscount = Binary::getWord($pct);
        $arcount = Binary::getWord($pct);
        for ($i = 0; $i < $qdcount; ++$i) {
            $name = Binary::parseLabels($pct, $orig);
            $typeInt = Binary::getWord($pct);
            $type = isset(Pool::$type[$typeInt]) ? Pool::$type[$typeInt] : 'UNK(' . $typeInt . ')';
            $classInt = Binary::getWord($pct);
            $class = isset(Pool::$class[$classInt]) ? Pool::$class[$classInt] : 'UNK(' . $classInt . ')';
            if (!isset($this->response[$type])) {
                $this->response[$type] = [];
            }
            $record = [
                'name' => $name,
                'type' => $type,
                'class' => $class,
            ];
            $this->response['query'][] = $record;
        }
        $getResRecord = function (&$pct) use ($orig) {
            $name = Binary::parseLabels($pct, $orig);
            $typeInt = Binary::getWord($pct);
            $type = isset(Pool::$type[$typeInt]) ? Pool::$type[$typeInt] : 'UNK(' . $typeInt . ')';
            $classInt = Binary::getWord($pct);
            $class = isset(Pool::$class[$classInt]) ? Pool::$class[$classInt] : 'UNK(' . $classInt . ')';
            $ttl = Binary::getDWord($pct);
            $length = Binary::getWord($pct);
            $data = mb_orig_substr($pct, 0, $length);
            $pct = mb_orig_substr($pct, $length);

            $record = [
                'name' => $name,
                'type' => $type,
                'class' => $class,
                'ttl' => $ttl,
            ];

            if (($type === 'A') || ($type === 'AAAA')) {
                if ($data === "\x00") {
                    $record['ip'] = false;
                    $record['ttl'] = 5;
                } else {
                    $record['ip'] = inet_ntop($data);
                }
            } elseif ($type === 'NS') {
                $record['ns'] = Binary::parseLabels($data, $orig);
            } elseif ($type === 'CNAME') {
                $record['cname'] = Binary::parseLabels($data, $orig);
            } elseif ($type === 'SOA') {
                $record['mname'] = Binary::parseLabels($data, $orig);
                $record['rname'] = Binary::parseLabels($data, $orig);
                $record['serial'] = Binary::getDWord($data);
                $record['refresh'] = Binary::getDWord($data);
                $record['retry'] = Binary::getDWord($data);
                $record['expire'] = Binary::getDWord($data);
                $record['nx'] = Binary::getDWord($data);
            } elseif ($type === 'MX') {
                $record['preference'] = Binary::getWord($data);
                $record['exchange'] = Binary::parseLabels($data, $orig);
            } elseif ($type === 'TXT') {
                $record['text'] = '';
                $lastLength = -1;
                while (($length = mb_orig_strlen($data)) > 0 && ($length !== $lastLength)) {
                    $record['text'] .= Binary::parseLabels($data, $orig);
                    $lastLength = $length;
                }
            } elseif ($type === 'SRV') {
                $record['priority'] = Binary::getWord($data);
                $record['weight'] = Binary::getWord($data);
                $record['port'] = Binary::getWord($data);
                $record['target'] = Binary::parseLabels($data, $orig);
            }

            return $record;
        };
        for ($i = 0; $i < $ancount; ++$i) {
            $record = $getResRecord($pct);
            if (!isset($this->response[$record['type']])) {
                $this->response[$record['type']] = [];
            }
            $this->response[$record['type']][] = $record;
        }
        for ($i = 0; $i < $nscount; ++$i) {
            $record = $getResRecord($pct);
            if (!isset($this->response[$record['type']])) {
                $this->response[$record['type']] = [];
            }
            $this->response[$record['type']][] = $record;
        }
        for ($i = 0; $i < $arcount; ++$i) {
            $record = $getResRecord($pct);
            if (!isset($this->response[$record['type']])) {
                $this->response[$record['type']] = [];
            }
            $this->response[$record['type']][] = $record;
        }
        $this->onResponse->executeOne($this->response);
        if (!$this->keepalive) {
            $this->finish();
            return;
        } else {
            $this->checkFree();
        }
    }
1315615
public function onRead()
    {
        packet:
        if ($this->state === self::STATE_STANDBY) {
            if ($this->bev->input->length < 4) {
                return;
            }
            $this->pctSize = Binary::bytes2int($this->read(3), true);
            $this->setWatermark($this->pctSize, $this->pctSize);
            $this->state = self::STATE_BODY;
            $this->seq = ord($this->read(1)) + 1;
        }
        /* STATE_BODY */
        $l = $this->bev->input->length;
        if ($l < $this->pctSize) {
            return;
        }
        $this->state = self::STATE_STANDBY;
        $this->setWatermark(4);
        if ($this->phase === 0) {
            $this->phase = self::PHASE_GOT_INIT;
            $this->protover = ord($this->read(1));
            if ($this->protover === 0xFF) { // error
                $fieldCount = $this->protover;
                $this->protover = 0;
                $this->onResponse->push(function ($conn, $result) {
                    if ($conn->onConnected) {
                        $conn->connected = true;
                        $conn->onConnected->executeAll($conn, $result);
                        $conn->onConnected = null;
                    }
                });
                goto field;
            }
            if (($p = $this->search("\x00")) === false) {
                $this->log('nul-terminator of \'serverver\' is not found');
                $this->finish();
                return;
            }
            $this->serverver = $this->read($p);
            $this->drain(1); // drain nul-byte
            $this->threadId = Binary::bytes2int($this->read(4), true);
            $this->scramble = $this->read(8);
            $this->drain(1); // ????

            $this->serverCaps = Binary::bytes2int($this->read(2), true);
            $this->serverLang = ord($this->read(1));
            $this->serverStatus = Binary::bytes2int($this->read(2), true);
            $this->drain(13);
            $restScramble = $this->read(12);
            $this->scramble .= $restScramble;
            $this->drain(1);

            $this->auth();
        } else {
            $fieldCount = ord($this->read(1));
            field:
            if ($fieldCount === 0xFF) {
                // Error packet
                $u = unpack('v', $this->read(2));
                $this->errno = $u[1];
                $state = $this->read(6);
                $this->errmsg = $this->read($this->pctSize - $l + $this->bev->input->length);
                $this->onError();
                $this->errno = 0;
                $this->errmsg = '';
            } elseif ($fieldCount === 0x00) {
                // OK Packet Empty
                if ($this->phase === self::PHASE_AUTH_SENT) {
                    $this->phase = self::PHASE_HANDSHAKED;

                    if ($this->dbname !== '') {
                        $this->query('USE `' . $this->dbname . '`');
                    }
                }

                $this->affectedRows = $this->parseEncodedBinary();

                $this->insertId = $this->parseEncodedBinary();

                $u = unpack('v', $this->read(2));
                $this->serverStatus = $u[1];

                $u = unpack('v', $this->read(2));
                $this->warnCount = $u[1];

                $this->message = $this->read($this->pctSize - $l + $this->bev->input->length);
                $this->onResultDone();
            } elseif ($fieldCount === 0xFE) {
                // EOF Packet
                if ($this->rsState === self::RS_STATE_ROW) {
                    $this->onResultDone();
                } else {
                    ++$this->rsState;
                }
            } else {
                // Data packet
                $this->prependInput(chr($fieldCount));

                if ($this->rsState === self::RS_STATE_HEADER) {
                    // Result Set Header Packet
                    $extra = $this->parseEncodedBinary();
                    $this->rsState = self::RS_STATE_FIELD;
                } elseif ($this->rsState === self::RS_STATE_FIELD) {
                    // Field Packet
                    $field = [
                        'catalog' => $this->parseEncodedString(),
                        'db' => $this->parseEncodedString(),
                        'table' => $this->parseEncodedString(),
                        'org_table' => $this->parseEncodedString(),
                        'name' => $this->parseEncodedString(),
                        'org_name' => $this->parseEncodedString()
                    ];

                    $this->drain(1); // filler

                    $u = unpack('v', $this->read(2));

                    $field['charset'] = $u[1];
                    $u = unpack('V', $this->read(4));
                    $field['length'] = $u[1];

                    $field['type'] = ord($this->read(1));

                    $u = unpack('v', $this->read(2));
                    $field['flags'] = $u[1];

                    $field['decimals'] = ord($this->read(1));

                    $this->resultFields[] = $field;
                } elseif ($this->rsState === self::RS_STATE_ROW) {
                    // Row Packet
                    $row = [];

                    for ($i = 0, $nf = sizeof($this->resultFields); $i < $nf; ++$i) {
                        $row[$this->resultFields[$i]['name']] = $this->parseEncodedString();
                    }

                    $this->resultRows[] = $row;
                }
            }
        }
        if ($this->finished) {
            return;
        }
        $this->drain($this->pctSize - $l + $this->bev->input->length); // drain the rest of packet
        goto packet;
    }
326417
public function writePCM($pcm)
    {
        if ($this->isClosed) {
            return;
        }

        if ($this->isPaused) {
            $this->pcmPauseBuffer[] = $pcm;

            return;
        }

        $this->pcmData .= $pcm;

        $this->emit('pcm', [$pcm]);
    }
1311131
public function sendBuffer($data)
    {
        if (! $this->ready) {
            return;
        }

        $packet = new VoicePacket($data, $this->ssrc, $this->seq, $this->timestamp, true, $this->secret_key);
        $this->client->send((string) $packet);

        $this->streamTime = microtime(true);

        $this->emit('packet-sent', [$packet]);
    }
426238
public function onReady()
    {
        $this->createXMLStream();
        $this->startXMLStream();
        $this->keepaliveTimer = setTimeout(function ($timer) {
            $this->ping();
        }, 1e6 * 30);
    }
1130244
void signalProtocolEstablished(String inboundProtocol) {
        assert !channel.isClientMode() : "Signal protocol should only be made on channel in serverMode";
        this.inboundProtocol = inboundProtocol;
        channel.outboundPipeline().wakeup();
    }
813288
public function sendPerformed(Swift_Events_SendEvent $evt)
    {
        ++$this->counter;
        if ($this->counter >= $this->threshold) {
            $transport = $evt->getTransport();
            $transport->stop();
            if ($this->sleep) {
                $this->sleep($this->sleep);
            }
            $transport->start();
            $this->counter = 0;
        }
    }
952869
async def _receive_packet(self, pkt):
        """"""
        packet_name = packet.packet_names[pkt.packet_type] \
            if pkt.packet_type < len(packet.packet_names) else 'UNKNOWN'
        self.logger.info(
            'Received packet %s data %s', packet_name,
            pkt.data if not isinstance(pkt.data, bytes) else '<binary>')
        if pkt.packet_type == packet.MESSAGE:
            await self._trigger_event('message', pkt.data, run_async=True)
        elif pkt.packet_type == packet.PONG:
            self.pong_received = True
        elif pkt.packet_type == packet.NOOP:
            pass
        else:
            self.logger.error('Received unexpected packet of type %s',
                              pkt.packet_type)
685547
private function _storePGT($pgt,$pgt_iou)
    {
        // ensure that storage is initialized
        $this->_initPGTStorage();
        // writes the PGT
        $this->_pgt_storage->write($pgt, $pgt_iou);
    }
483722
function onPeerConnected(peer)
    {
        if(scope.localStream)
        {
            peer.updateStream(scope.localStream,false);
        }
        scope._servConn.sendRTCState(true,peer.id);

        scope.dispatchEvent("peerConnected",peer.id);
    }
1023070
public function acceptUdpConnection($socket)
    {
        $recv_buffer = stream_socket_recvfrom($socket, static::MAX_UDP_PACKAGE_SIZE, 0, $remote_address);
        if (false === $recv_buffer || empty($remote_address)) {
            return false;
        }
        // UdpConnection.
        $connection           = new UdpConnection($socket, $remote_address);
        $connection->protocol = $this->protocol;
        if ($this->onMessage) {
            if ($this->protocol) {
                $parser      = $this->protocol;
                $recv_buffer = $parser::decode($recv_buffer, $connection);
            }
            ConnectionInterface::$statistics['total_request']++;
            try {
                call_user_func($this->onMessage, $connection, $recv_buffer);
            } catch (\Exception $e) {
                static::log($e);
                exit(250);
            } catch (\Error $e) {
                static::log($e);
                exit(250);
            }
        }
        return true;
    }
945032
public function onData($data)
    {
        //if we're in encryption stage decrypt it first
        if($this->secret !== null) {
            mcrypt_generic_init($this->encryptor, $this->secret, $this->secret);
            $data = mdecrypt_generic($this->encryptor, $data);
            mcrypt_generic_deinit($this->encryptor);
        }

        //attempt to parse the data as a packet
        try {

            //add the data to the current buffer
            $this->packetBuffer .= $data;

            //for as long as we have data left in the buffer
            do {

                //read the packet length from the stream
                $packetLengthVarInt = VarInt::readUnsignedVarInt($this->packetBuffer);

                //not enough data to read the packet length, wait for more data
                if($packetLengthVarInt === false) {
                    return;
                }

                //total length of the packet is the length of the varint + it's value
                $totalLength = $packetLengthVarInt->getDataLength() + $packetLengthVarInt->getValue();

                //if we don't have enough data to read the entire packet wait for more data to enter
                $bufferLength = strlen($this->packetBuffer);
                if ($bufferLength < $totalLength) {
                    return;
                }

                //remove the packet length varint from the buffer
                $this->packetBuffer = substr($this->packetBuffer, $packetLengthVarInt->getDataLength());

                //read the packet ID from the buffer
                $packetDataWithPacketID = substr($this->packetBuffer, 0, $packetLengthVarInt->getValue());

                //remove the rest of the packet from the buffer
                $this->packetBuffer = substr($this->packetBuffer, $packetLengthVarInt->getValue());

                //read the packet ID
                $packetID = VarInt::readUnsignedVarInt($packetDataWithPacketID);

                //get the raw packet data
                $packetData = substr($packetDataWithPacketID, $packetID->getDataLength());

                $this->lastPacket = $this->currentTime();

                //trigger packet processing
                $this->processPacket($packetID->getValue(), $packetData);

                //if we have buffer left run again
            } while (strlen($this->packetBuffer) > 0);

            //if any exceptions are thrown (error parsing the packets e.t.c.) send a disconnect packet
        } catch (Exception $ex) {
            echo "EXCEPTION IN PACKET PARSING {$ex->getMessage()}\n";
            echo $ex->getTraceAsString();
            $dis = new DisconnectPacket();
            $dis->setReason('Internal Server Error: '.$ex->getMessage());
            $this->end($dis->encodePacket());
        }
    }
716145
private function send(string $data):void
    {

        socket_write($this->socket, $data, strlen($data)) or $this->error();

    }
1181538
public function onRead()
    {
        if ($this->state === self::CONN_STATE_START) {
            if (($ver = $this->readline()) === null) {
                return;
            }
            $this->pool->setAmiVersion($this->addr, $ver);
            $this->state = self::CONN_STATE_GOT_INITIAL_PACKET;
            $this->auth();
        }

        while (($line = $this->readline()) !== null) {
            //Daemon::log('>>> '.$line);
            if ($line === '') {
                $this->instate = self::INPUT_STATE_END_OF_PACKET;
                $packet =& $this->packets[$this->cnt];
                ++$this->cnt;
            } else {
                $this->instate = self::INPUT_STATE_PROCESSING;
                list($header, $value) = Pool::extract($line);
                $this->packets[$this->cnt][$header] = $value;
            }

            if ((int)$this->state === self::CONN_STATE_AUTH) {
                if ($this->instate === self::INPUT_STATE_END_OF_PACKET) {
                    if ($packet['response'] === 'success') {
                        if ($this->state === self::CONN_STATE_CHALLENGE_PACKET_SENT) {
                            if (is_callable($this->onChallenge)) {
                                $func = $this->onChallenge;
                                $func($this, $packet['challenge']);
                            }
                        } else {
                            if ($packet['message'] === 'authentication accepted') {
                                $this->state = self::CONN_STATE_HANDSHAKED_OK;

                                Daemon::$process->log(
                                    __METHOD__ . ': Authentication ok. Connected to ' .
                                    parse_url($this->addr, PHP_URL_HOST)
                                );

                                if ($this->onConnected) {
                                    $this->connected = true;
                                    $this->onConnected->executeAll($this);
                                    $this->onConnected = null;
                                }

                                $this->event('connected');
                            }
                        }
                    } else {
                        $this->state = self::CONN_STATE_HANDSHAKED_ERROR;

                        Daemon::$process->log(
                            __METHOD__ . ': Authentication failed. Connection to ' .
                            parse_url($this->addr, PHP_URL_HOST) . ' failed.'
                        );

                        if ($this->onConnected) {
                            $this->connected = false;
                            $this->onConnected->executeAll($this);
                            $this->onConnected = null;
                        }

                        $this->finish();
                    }

                    $this->packets = [];
                }
            } elseif ($this->state === self::CONN_STATE_HANDSHAKED_OK) {
                if ($this->instate === self::INPUT_STATE_END_OF_PACKET) {
                    // Event
                    if (isset($packet['event']) && !isset($packet['actionid'])) {
                        $this->event('event_' . $packet['event'], $packet);
                        $this->event('event', $packet);
                    } // Response
                    elseif (isset($packet['actionid'])) {
                        $action_id =& $packet['actionid'];

                        if (isset($this->callbacks[$action_id])) {
                            if (isset($this->assertions[$action_id])) {
                                $this->packets[$action_id][] = $packet;

                                $assertations = count(
                                    array_uintersect_uassoc(
                                        $this->assertions[$action_id],
                                        $packet,
                                        'strcasecmp',
                                        'strcasecmp'
                                    )
                                );
                                if ($assertations === count($this->assertions[$action_id])) {
                                    if (is_callable($this->callbacks[$action_id])) {
                                        $this->callbacks[$action_id]($this, $this->packets[$action_id]);
                                        unset($this->callbacks[$action_id]);
                                    }

                                    unset($this->assertions[$action_id]);
                                    unset($this->packets[$action_id]);
                                }
                            } else {
                                if (is_callable($this->callbacks[$action_id])) {
                                    $this->callbacks[$action_id]($this, $packet);
                                    unset($this->callbacks[$action_id]);
                                }
                            }
                        }
                    }

                    unset($packet);
                    unset($this->packets[$this->cnt - 1]);
                }
            }
        }
    }
1222951
public function send(string $protocol)
    {
        header("$protocol {$this->statusCode} {$this->statusText}");
        foreach ($this->headers->getStringifiedArray() as $header) {
            header($header);
        }

        echo $this->body;
    }
877604
public function send(string $str): void
    {
        if ($this->need_headers) {
            $this->sendHttpHeaders();
        }
        $this->need_headers = false;

        fwrite($this->opt->getOutputStream(), $str);
    }
34353
public function setOptInStatus($iStatus)
    {
        $this->oxnewssubscribed__oxdboptin = new \OxidEsales\Eshop\Core\Field($iStatus, \OxidEsales\Eshop\Core\Field::T_RAW);
        $this->save();
    }