Exemple #1
0
 function request($method, $uri)
 {
     $coapRequest = new CoapRequest($uri, $method, '');
     $coapRequest->setCode($method);
     $coapRequest->setType(CoapRequest::CON);
     return new Request($this->connector, $coapRequest);
 }
Exemple #2
0
 function handlePacket($pkt)
 {
     $this->request = CoapRequest::fromBinString($pkt);
     if ($this->state == self::STATE_INIT) {
         $this->state = self::STATE_RESP_PENDING;
         $resp = new CoapResponse();
         $resp->setMessageId($this->request->getMessageId());
         if ($this->request->getType() == CoapRequest::NON) {
             $resp->setType(CoapResponse::NON);
         } elseif ($this->request->getType() == CoapRequest::CON) {
             $resp->setType(CoapResponse::ACK);
         } else {
             $this->sendAck($this->request, '5.00');
             $this->emit('error', array($this->request));
             return;
         }
         $resp->setCode('2.00');
         $this->emit('request', array($this->request, $resp, $this));
         return;
     }
     if ($this->request->getType() == CoapRequest::ACK && $this->state == self::STATE_WAITING_ACK) {
         $this->close();
         $this->state = self::STATE_WAITING_CLOSE;
         return;
     }
 }