• 25-02-2014, 14:05:47
    #1
    Çok uzun süredir tcp protokolü üzerinden veri göndermeye çalışıyorum ama bir türlü gönderemedim.

    hedef ip ve portuna aşagıdaki gibi bir komut göndermek istiyorum ama bir türlü gönderemedim.

    Sanırım TCP ile önce ascii ye donusturup daha sonra byte olarak veri göndemek gerekiyormuş. Sizce nasıl yapabilirim?


    ³UU³³1³1³³M³28/02/2014³18:00³25/02/2014³09:00³³³0³0³0³0³0³7³³³³³³³³³³
  • 25-02-2014, 15:53:17
    #2
    nurettin adlı üyeden alıntı: mesajı görüntüle
    Sanırım TCP ile önce ascii ye donusturup daha sonra byte olarak veri göndemek gerekiyormuş. Sizce nasıl yapabilirim?

    ³UU³³1³1³³M³28/02/2014³18:00³25/02/2014³09:00³³³0³0³0³0³0³7³³³³³³³³³³
    <?
    $host = '127.0.0.1';
    $port = 1234;
    $data = '³UU³³1³1³³M³28/02/2014³18:00³25/02/2014³09:00³³³0³0³0³0³0³7³³³³³³³³³³';
    
    $socket = fsockopen($host, $port);
    
    $characters = preg_split('//u', $data, -1, PREG_SPLIT_NO_EMPTY);
    foreach($characters as $character)
    {
      list(, $code) = unpack('N', mb_convert_encoding($character, 'UCS-4BE', 'UTF-8'));
      fwrite($socket, $code);
      fflush($socket);
    }
    
    fclose($socket);
    ?>
  • 25-02-2014, 21:22:53
    #3
    ilginiz için teşekkurler ama çalışmadı

    tcp ye bu mesaj şu şekilde gidecekmiş.

    Alıntı
    STX¦[PC Id¦]RC¦Message¦ETX LRC
    Dökümasyon sistemini inceledim ama bu konuyu çözemedim.

    http://mobildepo.org/tcp/dokuman/1.pdf

    http://mobildepo.org/tcp/dokuman/2.pdf
  • 26-02-2014, 10:19:27
    #4
    nurettin adlı üyeden alıntı: mesajı görüntüle
    tcp ye bu mesaj şu şekilde gidecekmiş.

    Alıntı
    STX¦[PC Id¦]RC¦Message¦ETX LRC
    PHP'nin sunduğu yerleşik imkanlar -diğer dillere nazaran- bu tür işlemler için yetersiz kalıyor. Bu sebepten dolayı, "PHP ile Online Okey" projesi için yazdığım SimpleByteArray adındaki sınıfı kullanmanızda yarar görüyorum. Gönderilecek verilerin 'byte' olarak okunacağını varsayarak byte değerinde yazdırdım. Ancak bu değerler 'short' veya 'integer' olarak da kabul edililyor olabilir. Bunun için dökümanlarda daha ayrıntılı bir inceleme yapmanız gerekli. Ayrıca yazılan 'string' değerinin sunucu üzerinde nasıl okunacağından emin değilim. Normal şartlarda gerekli byte verileri okunduktan sonra string değeri 'null' bir byte(0x00) ile kaşılaşılıncaya kadar okunur. Ancak bu null değer, sizin sunucunuzda paket sonu anlamına da gelebilir. Buna dikkat ederek mümkünse ilk teslerinizde sadece sayısal değer gönderin ve literal değerleri bunları çalıştırdıktan sonra test edin. Ayrıca literal değerlerdeki karakter kodlamaları byte olarak yapılıyor. Bu yüzden unicode karakterleri kullanamazsınız. Ancak sunucunuzun da bu şekilde çalışıyor olma ihtimali yüksek. Eğer bu konuda bir sorun yaşarsanız string değerlerini, byte yerine short olarak yazdırın. Böylece UTF 8 desteğini de sağlayabilirsiniz.

    [PC Id¦]RC değerleri değişken olduğu için bunları size bırakıyorum.

    Daha ayrıntılı bir bilgi alış-verişi ve daha fazla kontrol istiyorsanız, projedeki, MMOCore kütüphanesine ait diğer sınıfları da incelyebilirsiniz.

    <?
    define('STX', 0x02);
    define('ETX', 0x03);
    define('LRC', 0x0D);
    
    $host   = '127.0.0.1';
    $port   = 1234;
    $socket = fsockopen($host, $port);
    
    $packet = new SimpleByteArray();
    $packet->write_byte(STX); // STX
    $packet->write_string('Message.'); // Message
    $packet->write_byte(ETX); // ETX
    $packet->write_byte(LRC); //LRC
    
    @socket_write($socket, $packet, strlen($packet));
    @fflush($socket);
    @fclose($socket);
    ?>

    <?
    /**
     * @property int[] $_bytes
     * @property int   $_position
     */
    class SimpleByteArray
    {
      protected $_bytes;
      protected $_position = 0;
    
      /**
       * @param int[]|null $bytes
       */
      public function __construct($bytes = NULL)
      {
        if($bytes && !is_array($bytes))
          throw new SimpleByteArrayException('Sadece byte dizisi kullanabilirisiniz.');
    
        $this->_bytes = $bytes;
      }
    
      /**
       * @return int
       */
      public function get_position()
      {
        return $this->_position;
      }
    
      /**
       * @param int $position
       */
      public function set_position($position)
      {
        $this->_position = $position;
      }
    
      /**
       * @return \int[]
       */
      public function bytes()
      {
        return $this->_bytes;
      }
    
      /**
       * @return int
       */
      public function length()
      {
        return count($this->_bytes);
      }
    
      /**
       * @return int
       */
      public function bytes_available()
      {
        return $this->length() - $this->get_position();
      }
    
      /**
       * @param int $val
       */
      public function write_byte($val)
      {
        $this->_bytes[$this->_position++] = $val >> 0 & 0xFF;
      }
    
      /**
       * @param SimpleByteArray $source
       * @param int             $position
       * @param int             $limit
       *
       * @throws SimpleByteArrayException
       */
      public function write_bytes($source, $position, $limit)
      {
        if($position < 0)
          throw new SimpleByteArrayException("İmleç sıfırdan küçük olamaz. {$position}");
    
        if($limit < 0)
          throw new SimpleByteArrayException("Limit sıfırdan küçük olamaz. {$limit}");
    
        if($position > $source->length())
          throw new SimpleByteArrayException("İmleç dizin uzunluğundan büyük olamaz. {$position} : {$source->length()}");
    
        if($position + $limit > $source->length())
          throw new SimpleByteArrayException("İmleç ve limit toplamı dizinin uzunluğundan büyük olamaz. {$position} :{$limit} : {$source->length()}");
    
        $source->set_position($position);
    
        for($i = 0; $i < $limit; $i++)
          $this->write_byte($source->read_byte());
      }
    
      /**
       * @param int $val
       */
      public function write_boolean($val)
      {
        $this->_bytes[$this->_position++] = $val ? 0x01 : 0x00;
      }
    
      /**
       * @param int $val
       */
      public function write_short($val)
      {
        $this->_bytes[$this->_position++] = $val >> 8 & 0xFF;
        $this->_bytes[$this->_position++] = $val >> 0 & 0xFF;
      }
    
      /**
       * @param int $val
       */
      public function write_int($val)
      {
        $this->_bytes[$this->_position++] = $val >> 24;
        $this->_bytes[$this->_position++] = $val >> 16;
        $this->_bytes[$this->_position++] = $val >> 8;
        $this->_bytes[$this->_position++] = $val >> 0;
      }
    
      /**
       * @param string $val
       */
      public function write_string($val)
      {
        $val          = $val ? $val : '';
        $string_array = str_split($val);
    
        foreach($string_array as $letter)
          $this->write_byte(ord($letter));
    
        $this->write_byte(0x00);
      }
    
      /**
       * @return int
       */
      public function read_byte()
      {
        return $this->read_next() << 0;
      }
    
      /**
       * @return bool
       */
      public function read_bool()
      {
        return $this->read_next() << 0 == 0x01;
      }
    
      /**
       * @param SimpleByteArray $byte_array
       * @param int             $position
       * @param int             $limit
       *
       * @throws SimpleByteArrayException
       */
      public function read_bytes($byte_array, $position = 0, $limit = 0)
      {
        if($position < 0)
          throw new SimpleByteArrayException('İmleç sıfırdan küçük olamaz.');
    
        if($limit < 0)
          throw new SimpleByteArrayException('Limit sıfırdan küçük olamaz.');
    
        if($position > $byte_array->length())
          throw new SimpleByteArrayException("İmleç dizin uzunluğundan büyük olamaz. {$position} : {$byte_array->length()}");
    
        if($position + $limit > $byte_array->length())
          throw new SimpleByteArrayException("İmleç ve limit toplamı dizinin uzunluğundan büyük olamaz. {$position} :{$limit} : {$byte_array->length()}");
    
        $this->set_position($position);
    
        for($i = 0; $i < $limit; $i++)
          $byte_array->write_byte($this->read_byte());
      }
    
      /**
       * @return int
       */
      public function read_short()
      {
        $short = $this->read_next() << 8;
        $short += $this->read_next() << 0;
    
        return $short;
      }
    
      /**
       * @return int
       */
      public function read_int()
      {
        $int = $this->read_next() << 24;
        $int += $this->read_next() << 16;
        $int += $this->read_next() << 8;
        $int += $this->read_next() << 0;
    
        return $int;
      }
    
      /**
       * @return string
       */
      public function read_string()
      {
        $string = '';
    
        while($ord = $this->read_byte())
          $string .= chr($ord);
    
        return $string;
      }
    
      /**
       * @return int
       *
       * @throws SimpleByteArrayException
       */
      private function read_next()
      {
        if($this->get_position() > $this->length())
          throw new SimpleByteArrayException('Dizin sonuna ulaşildi.');
    
        return $this->_bytes[$this->_position++];
      }
    
      /**
       * @return string
       */
      public function __toString()
      {
        $original_position = $this->get_position();
        $out               = '';
    
        $this->set_position(0);
    
        while($this->bytes_available())
          $out .= pack('c', $this->read_byte());
    
        $this->set_position($original_position);
    
        return $out;
      }
    }
    ?>
  • 26-02-2014, 10:54:43
    #5
    nurettin adlı üyeden alıntı: mesajı görüntüle
    Çok uzun süredir tcp protokolü üzerinden veri göndermeye çalışıyorum ama bir türlü gönderemedim.

    hedef ip ve portuna aşagıdaki gibi bir komut göndermek istiyorum ama bir türlü gönderemedim.

    Sanırım TCP ile önce ascii ye donusturup daha sonra byte olarak veri göndemek gerekiyormuş. Sizce nasıl yapabilirim?


    ³UU³³1³1³³M³28/02/2014³18:00³25/02/2014³09:00³³³0³0³0³0³0³7³³³³³³³³³³
    neden veri göndermeye çalışıyorsunuz.
  • 26-02-2014, 12:34:49
    #6
    PsiCat adlı üyeden alıntı: mesajı görüntüle
    PHP'nin sunduğu yerleşik imkanlar -diğer dillere nazaran- bu tür işlemler için yetersiz kalıyor. Bu sebepten dolayı, "PHP ile Online Okey" projesi için yazdığım SimpleByteArray adındaki sınıfı kullanmanızda yarar görüyorum. Gönderilecek verilerin 'byte' olarak okunacağını varsayarak byte değerinde yazdırdım. Ancak bu değerler 'short' veya 'integer' olarak da kabul edililyor olabilir. Bunun için dökümanlarda daha ayrıntılı bir inceleme yapmanız gerekli. Ayrıca yazılan 'string' değerinin sunucu üzerinde nasıl okunacağından emin değilim. Normal şartlarda gerekli byte verileri okunduktan sonra string değeri 'null' bir byte(0x00) ile kaşılaşılıncaya kadar okunur. Ancak bu null değer, sizin sunucunuzda paket sonu anlamına da gelebilir. Buna dikkat ederek mümkünse ilk teslerinizde sadece sayısal değer gönderin ve literal değerleri bunları çalıştırdıktan sonra test edin. Ayrıca literal değerlerdeki karakter kodlamaları byte olarak yapılıyor. Bu yüzden unicode karakterleri kullanamazsınız. Ancak sunucunuzun da bu şekilde çalışıyor olma ihtimali yüksek. Eğer bu konuda bir sorun yaşarsanız string değerlerini, byte yerine short olarak yazdırın. Böylece UTF 8 desteğini de sağlayabilirsiniz.
    şu ana kadar aldıgımız en açıklayıcı cevabı verdiniz. Teşekkur ederim

    Dememde şu şekilde yaptım ama yinede bir sonuç alamadım.

    Bu kodada tek değişken tarih değişkeni olacak digerleri hep standart kalacak. bu kodları kendi emulatörü üzerinden gönderdigimde almış oldugum cevaptı

    <?php
    // Kütüphane bilgisi
    define('STX', 0x02); 
    define('ETX', 0x03); 
    define('LRC', 0x0D); 
    
    $host   = '127.0.0.1'; 
    $port   = 7777; 
    $socket = fsockopen($host, $port); 
    
    $packet = new SimpleByteArray(); 
    $packet->write_byte(STX); // STX 
    $packet->write_string('³UU³³1³1³³P³26/02/2014³09:32³28/02/2014³09:32³³³0³0³0³0³0³7³³³³³³³³³³'); // Message 
    $packet->write_byte(ETX); // ETX 
    $packet->write_byte(LRC); //LRC 
    
    @socket_write($socket, $packet, strlen($packet)); 
    @fflush($socket); 
    @fclose($socket); 
    ?>
  • 26-02-2014, 17:16:20
    #7
    wpe pro programını indirkten sonra

    Wpe pro indirme adresi: http://dosya.co:7080/cgi-bin/dl.cgi/...o%20Trgala.zip

    programın kendi emülatörü üzerinden kod gönderdim. Bu kod başarılı bir sonuç veriyor.

    bu kodu php ile göndermem gerekiyor.

    Gönderdigim kod:
    ³UU³³1³1³³P³26/02/2014³09:00³28/02/2014³12:30³³³0³0³0³0³0³7³³³³³³³³³³

    Wpe pro çıktısı


  • 26-02-2014, 18:19:30
    #8
    nurettin adlı üyeden alıntı: mesajı görüntüle
    programın kendi emülatörü üzerinden kod gönderdim. Bu kod başarılı bir sonuç veriyor.

    bu kodu php ile göndermem gerekiyor.

    Gönderdigim kod:
    ³UU³³1³1³³P³26/02/2014³09:00³28/02/2014³12:30³³³0³0³0³0³0³7³³³³³³³³³³

    Bu yeterli bir bilgi. Sorun, daha önceki mesajımda da belirttiğim gibi SimpleByteArray sınıfını yazarken unicode desteğini sunmamamış olmam. Ayrıca belirttiğim diğer bir husus da söz konusu; string türünün sunucuda null bir byte ile sonlandırılmaması. Bu hususları düzeltmek için, write_string metodunun altına aşağıdaki metodu ekleyin;

      /**
       * @param string $val
       * @param bool   $null_terminator
       */
      public function write_mb_string($val, $null_terminator = true)
      {
        $val          = $val ? $val : '';
        $string_array = preg_split('//u', $val, -1, PREG_SPLIT_NO_EMPTY);
    
        foreach($string_array as $letter)
        {
          list(, $code) = unpack('N', mb_convert_encoding($letter, 'UCS-4BE', 'UTF-8'));
          $this->write_byte($code);
        }
    
        if($null_terminator)
          $this->write_byte(0x00);
      }
    Paketi göndermek istediğiniz noktadaki kodlarınızı da şu şekilde değiştirin;

    <?
    define('STX', 0x02);
    define('ETX', 0x03);
    define('LRC', 0x0D);
    
    $host   = '127.0.0.1';
    $port   = 1234;
    $socket = fsockopen($host, $port);
    
    $packet = new SimpleByteArray();
    $packet->write_byte(STX); // STX
    $packet->write_mb_string('³UU³³1³1³³P³26/02/2014³09:32³28/02/2014³09:32³³³0³0³0³0³0³7³³³³³³³³³³', false); // Message
    $packet->write_byte(ETX); // ETX
    $packet->write_byte(LRC); //LRC
    
    @socket_write($socket, $packet, strlen($packet));
    @fflush($socket);
    @fclose($socket);
    ?>
    
    <h3>Paket Dokumu:</h3>
    <pre>
    <?
    $bytes = $packet->bytes();
    
    for($i = 0; $i < count($bytes); $i++)
    {
      $hex_val = str_pad(strtoupper(dechex($bytes[$i])), 2, 0, STR_PAD_LEFT);
      echo "{$hex_val} ";
    
      if(!$i) continue;
      if(($i + 1) % 16 == 0) echo PHP_EOL;
    }
    ?>
    </pre>
    Alacağınız sonuç aşağıdaki gibi olmalı;
    Paket Dokumu:
    
    02 B3 55 55 B3 B3 31 B3 31 B3 B3 50 B3 32 36 2F 
    30 32 2F 32 30 31 34 B3 30 39 3A 33 32 B3 32 38 
    2F 30 32 2F 32 30 31 34 B3 30 39 3A 33 32 B3 B3 
    B3 30 B3 30 B3 30 B3 30 B3 30 B3 37 B3 B3 B3 B3 
    B3 B3 B3 B3 B3 B3 03 0D
  • 26-02-2014, 18:52:59
    #9
    kodları dediğiniz gibi düzenledim çıkan sonuç şu şekilde oldu:

    Alıntı
    00 B3 55 55 B3 B3 31 B3 31 B3 B3 50 B3 32 36 2F
    30 32 2F 32 30 31 34 B3 30 39 3A 33 32 B3 32 38
    2F 30 32 2F 32 30 31 34 B3 30 39 3A 33 32 B3 B3
    B3 30 B3 30 B3 30 B3 30 B3 30 B3 37 B3 B3 B3 B3
    B3 B3 B3 B3 B3 B3 00 00
    STX, ETX Ve LRC leri tırnak içine aldım. almadığım takdirde hata veriyordu. chr(2) şeklinde de yazdıgımda aynı sonucu aldım.

    <?php
    class SimpleByteArray 
    { 
      protected $_bytes; 
      protected $_position = 0; 
    
      /** 
       * @param int[]|null $bytes 
       */ 
      public function __construct($bytes = NULL) 
      { 
        if($bytes && !is_array($bytes)) 
          throw new SimpleByteArrayException('Sadece byte dizisi kullanabilirisiniz.'); 
    
        $this->_bytes = $bytes; 
      } 
    
      /** 
       * @return int 
       */ 
      public function get_position() 
      { 
        return $this->_position; 
      } 
    
      /** 
       * @param int $position 
       */ 
      public function set_position($position) 
      { 
        $this->_position = $position; 
      } 
    
      /** 
       * @return \int[] 
       */ 
      public function bytes() 
      { 
        return $this->_bytes; 
      } 
    
      /** 
       * @return int 
       */ 
      public function length() 
      { 
        return count($this->_bytes); 
      } 
    
      /** 
       * @return int 
       */ 
      public function bytes_available() 
      { 
        return $this->length() - $this->get_position(); 
      } 
    
      /** 
       * @param int $val 
       */ 
      public function write_byte($val) 
      { 
        $this->_bytes[$this->_position++] = $val >> 0 & 0xFF; 
      } 
    
      /** 
       * @param SimpleByteArray $source 
       * @param int             $position 
       * @param int             $limit 
       * 
       * @throws SimpleByteArrayException 
       */ 
      public function write_bytes($source, $position, $limit) 
      { 
        if($position < 0) 
          throw new SimpleByteArrayException("İmleç sıfırdan küçük olamaz. {$position}"); 
    
        if($limit < 0) 
          throw new SimpleByteArrayException("Limit sıfırdan küçük olamaz. {$limit}"); 
    
        if($position > $source->length()) 
          throw new SimpleByteArrayException("İmleç dizin uzunluğundan büyük olamaz. {$position} : {$source->length()}"); 
    
        if($position + $limit > $source->length()) 
          throw new SimpleByteArrayException("İmleç ve limit toplamı dizinin uzunluğundan büyük olamaz. {$position} :{$limit} : {$source->length()}"); 
    
        $source->set_position($position); 
    
        for($i = 0; $i < $limit; $i++) 
          $this->write_byte($source->read_byte()); 
      } 
    
      /** 
       * @param int $val 
       */ 
      public function write_boolean($val) 
      { 
        $this->_bytes[$this->_position++] = $val ? 0x01 : 0x00; 
      } 
    
      /** 
       * @param int $val 
       */ 
      public function write_short($val) 
      { 
        $this->_bytes[$this->_position++] = $val >> 8 & 0xFF; 
        $this->_bytes[$this->_position++] = $val >> 0 & 0xFF; 
      } 
    
      /** 
       * @param int $val 
       */ 
      public function write_int($val) 
      { 
        $this->_bytes[$this->_position++] = $val >> 24; 
        $this->_bytes[$this->_position++] = $val >> 16; 
        $this->_bytes[$this->_position++] = $val >> 8; 
        $this->_bytes[$this->_position++] = $val >> 0; 
      } 
    
      /** 
       * @param string $val 
       */ 
      public function write_string($val) 
      { 
        $val          = $val ? $val : ''; 
        $string_array = str_split($val); 
    
        foreach($string_array as $letter) 
          $this->write_byte(ord($letter)); 
    
        $this->write_byte(0x00); 
      } 
    
      /** 
       * @return int 
       */ 
      public function read_byte() 
      { 
        return $this->read_next() << 0; 
      } 
    
      /** 
       * @return bool 
       */ 
      public function read_bool() 
      { 
        return $this->read_next() << 0 == 0x01; 
      } 
    
      /** 
       * @param SimpleByteArray $byte_array 
       * @param int             $position 
       * @param int             $limit 
       * 
       * @throws SimpleByteArrayException 
       */ 
      public function read_bytes($byte_array, $position = 0, $limit = 0) 
      { 
        if($position < 0) 
          throw new SimpleByteArrayException('İmleç sıfırdan küçük olamaz.'); 
    
        if($limit < 0) 
          throw new SimpleByteArrayException('Limit sıfırdan küçük olamaz.'); 
    
        if($position > $byte_array->length()) 
          throw new SimpleByteArrayException("İmleç dizin uzunluğundan büyük olamaz. {$position} : {$byte_array->length()}"); 
    
        if($position + $limit > $byte_array->length()) 
          throw new SimpleByteArrayException("İmleç ve limit toplamı dizinin uzunluğundan büyük olamaz. {$position} :{$limit} : {$byte_array->length()}"); 
    
        $this->set_position($position); 
    
        for($i = 0; $i < $limit; $i++) 
          $byte_array->write_byte($this->read_byte()); 
      } 
    
      /** 
       * @return int 
       */ 
      public function read_short() 
      { 
        $short = $this->read_next() << 8; 
        $short += $this->read_next() << 0; 
    
        return $short; 
      } 
    
      /** 
       * @return int 
       */ 
      public function read_int() 
      { 
        $int = $this->read_next() << 24; 
        $int += $this->read_next() << 16; 
        $int += $this->read_next() << 8; 
        $int += $this->read_next() << 0; 
    
        return $int; 
      } 
    
      /** 
       * @return string 
       */ 
      public function read_string() 
      { 
        $string = ''; 
    
        while($ord = $this->read_byte()) 
          $string .= chr($ord); 
    
        return $string; 
      } 
    
      /** 
       * @return int 
       * 
       * @throws SimpleByteArrayException 
       */ 
      private function read_next() 
      { 
        if($this->get_position() > $this->length()) 
          throw new SimpleByteArrayException('Dizin sonuna ulaşildi.'); 
    
        return $this->_bytes[$this->_position++]; 
      } 
    
      /** 
       * @return string 
       */ 
      public function __toString() 
      { 
        $original_position = $this->get_position(); 
        $out               = ''; 
    
        $this->set_position(0); 
    
        while($this->bytes_available()) 
          $out .= pack('c', $this->read_byte()); 
    
        $this->set_position($original_position); 
    
        return $out; 
      } 
    
        public function write_mb_string($val, $null_terminator = true) 
      { 
        $val          = $val ? $val : ''; 
        $string_array = preg_split('//u', $val, -1, PREG_SPLIT_NO_EMPTY); 
    
        foreach($string_array as $letter) 
        { 
          list(, $code) = unpack('N', mb_convert_encoding($letter, 'UCS-4BE', 'UTF-8')); 
          $this->write_byte($code); 
        } 
    
        if($null_terminator) 
          $this->write_byte(0x00); 
      }  
       
    } 
    
    
    
    $host   = '127.0.0.1'; 
    $port   = 7777; 
    $socket = fsockopen($host, $port); 
    
    $packet = new SimpleByteArray(); 
    $packet->write_byte('STX'); // STX 
    $packet->write_mb_string('³UU³³1³1³³P³26/02/2014³09:32³28/02/2014³09:32³³³0³0³0³0³0³7³³³³³³³³³³', false); // Message 
    $packet->write_byte('ETX'); // ETX 
    $packet->write_byte('LRC'); //LRC 
    
    @socket_write($socket, $packet, strlen($packet)); 
    @fflush($socket); 
    @fclose($socket); 
    ?> 
    
    <h3>Paket Dokumu:</h3> 
    <pre> 
    <?php
    $bytes = $packet->bytes(); 
    
    for($i = 0; $i < count($bytes); $i++) 
    { 
      $hex_val = str_pad(strtoupper(dechex($bytes[$i])), 2, 0, STR_PAD_LEFT); 
      echo "{$hex_val} "; 
    
      if(!$i) continue; 
      if(($i + 1) % 16 == 0) echo PHP_EOL; 
    } 
    ?> 
    </pre>