php java writeInt,

0 Cevap java

hey all i am trying to make a data output stream in php to write back primitive data types to a java application

i created a class that write the data to an array (write it same as java do , copy from java code)

ve nihayet ben müşteriye diziyi tekrar yazıyorum.

onun iyi çalışmıyor gibi hissediyor

for example the writeInt method send to the java client some wrong values am i doing ok ?

teşekkür ederim

İşte benim kod

private $buf   = array();


public function writeByte($b) {
  $this->buf[] = pack('c' ,$b);
}

public function writeInt($v) { 
  $this->writeByte($this->shiftRight3($v , 24) & 0xFF);
  $this->writeByte($this->shiftRight3($v , 16) & 0xFF);
  $this->writeByte($this->shiftRight3($v ,  8) & 0xFF);
  $this->writeByte($this->shiftRight3($v ,  0) & 0xFF);

}


private function shiftRight3($a ,$b){
  if(is_numeric($a) && $a < 0){
    return ($a >> $b) + (2<<~$b);
  }else{
    return ($a >> $b);
  }
}


public function toByteArray(){
    return $this->buf;
}

bu i ana php dosyasını kuruyorum nasıl

   header("Content-type: application/octet-stream" ,true);
   header("Content-Transfer-Encoding: binary" ,true);

Bu i verileri dönen nasıl

  $arrResult = $dataOutputStream->toByteArray();
  for ($i = 0 ; $i < count($arrResult) ; $i ++){
     echo $arrResult[$i];
  }

I EDIT THE QUESTION ,ACCOURDING TO MY CODE CHANGING in the java client side seems that i have 2 bytes to read start always i have 13 , 10 , which is \r \n how come i am reading them always ?

(Benim test i, java istemci tarafında bir bayt yolluyorum

  URL u = new URL("http://localhost/jtpc/test/inputTest.php");
  URLConnection c = u.openConnection();

  InputStream in =  c.getInputStream();
  int read = 0;
  for (int j = 0; read != -1 ; j++) {
    read = in.read();
    System.out.println("More to read : " + read);
  }
 )

  the output will be ,
   More to read : 13
   More to read : 10
   More to read : 1 (this is the byte i am sending)

0 Cevap