Ok, I thing that created correct packet, packet size seems correct so why server returned result once and then each another request now does not return anything?
Here is my corrected code, is something wrong here?:
<?php
require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'word.class.php';
class Packet {
public $words = array();
protected $size = 0;
protected $is_request;
protected $from_client;
/**
* Construct packet
*
* @param bool $is_request
* @param bool $is_client
* @param string $command
*/
public function __construct($is_request, $from_client, $command) {
$this->is_request = $is_request;
$this->from_client = $from_client;
$this->size +=4 ; // size of first paremeter (4 bytes integer)
$command = trim(preg_replace('!\s+!', ' ', $command)); // remove double spaces
$this->size += strlen( str_ireplace(' ', '', $command) ) ; // size of words
$this->words = explode(' ',$command);
$this->size += count($this->words)*5; // add size of each word size + null byte (5 bytes for each word)
$this->size += 4; // add size of packet size
$this->size += 4; // size of words count
}
/**
* Return words packet string
*
* @return String
*/
protected function getWords(){
$result = '';
foreach($this->words AS $word) {
$word = new Word($word);
$result.= $word->pack();
}
return $result;
}
/**
* Return packet for sending
*
* @return string
*/
public function pack() {
return pack('C4VV', (int)$this->is_request, (int)$this->from_client, 0, 0, $this->size, count($this->words) ).$this->getWords();
}
public function getSize(){
return $this->size;
}
}