无法取消屏蔽Web套接字中的一帧以上

时间:2018-10-19 07:18:28

标签: php phpwebsocket

我在通过PHP服务器中的socket_recv接收帧时遇到问题。当我一次从客户端发送多于1条消息时出现问题(例如循环)

如果循环是我得到的10倍,则decMessages中仅返回1;当我打印有效负载时,它一次仅显示2条消息。

function unmask($payload) {


$tempCount=0;
$decMessages = Array();  
do 
{ // This should be running until all frames are unmasked and added to $decMessages Array 
    $tempCount++;
    $length = ord($payload[1]) & 127;
    $temp_variable = 0;
    if($length == 126) {
      $temp_variable = 4;   
      $masks = substr($payload, 4, 4);
      $data = substr($payload, 8);
      $len = (ord($payload[2]) << 8) + ord($payload[3]);
    }elseif($length == 127) {
      $temp_variable = 14;  
      $masks = substr($payload, 10, 4);
      $data = substr($payload, 14);
      $len = (ord($payload[2]) << 56) + (ord($payload[3]) << 48) +
          (ord($payload[4]) << 40) + (ord($payload[5]) << 32) +
          (ord($payload[6]) << 24) +(ord($payload[7]) << 16) +
          (ord($payload[8]) << 8) + ord($payload[9]);
    }else {        
      $temp_variable = 6;       
      $masks = substr($payload, 2, 4);
      $data = substr($payload, 6);
      $len = $length;
    }

    $payload = '';
    for ($i = 0; $i < $len; ++$i) {    
      $payload .= $data[$i] ^ $masks[$i%4];
    }
    echo "This is payload".$payload."\n\r";
    echo "This is Count ".count($decMessages)."\n\r";
    echo "This is temp ".$tempCount."\n\r";

    $decMessages[] = $payload;


    $payload = substr($payload, $len+$temp_variable, strlen($payload));     
}
while (($len < strlen($data)) && $tempCount<10);

//echo "\n" . count($decMessages) . "\n";

return $decMessages;

}

0 个答案:

没有答案