exiledscot / phpwebsocket

Automatically exported from code.google.com/p/phpwebsocket
0 stars 0 forks source link

onmessage being called multiple times #31

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
For long strings, the onmessage handler is called multiple times which is 
causing problems.  I tried to increase the buffer size in the websocket class:

$bytes = @socket_recv($socket,$buffer,50000,0);

That didn't help.

Any ideas?

Original issue reported on code.google.com by zar...@gmail.com on 2 May 2011 at 4:58

GoogleCodeExporter commented 8 years ago
So right now it sends a maximum of 32767 bytes in one call.  This would be 
fine, except that in the second call which would send the remaining bit of 
data, there are bytes missing as described here:

http://stackoverflow.com/questions/5857406/bytes-missing-between-websocket-calls

Original comment by zar...@gmail.com on 2 May 2011 at 2:14

GoogleCodeExporter commented 8 years ago
Related issue, when onmessage is being called multiple times, every call except 
the first has its first byte missing.  No idea how to fix.  Also don't know 
what the purpose of the following line of code is the unwrap():

return substr($msg,1,strlen($msg)-2);

Why is it shaving off two characters at the end? Shouldn't it just shave off 
the the chr(255)?

Original comment by zar...@gmail.com on 3 May 2011 at 4:26

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Hi, I encounter the same issue and simply solve it by change the unwrap 
function to this :

  function  unwrap($msg=""){
    $firstChar = substr($msg,0,1);
    $lastChar = substr($msg,-1);
    if ($firstChar==chr(0) && $lastChar==chr(255))
      return substr($msg,1,strlen($msg)-2);
    elseif ($firstChar==chr(0))
      return substr($msg,1);
    else
      return substr($msg,0,strlen($msg)-1);
  }

this function should delete the chr(0) in the head and the chr(255) in the 
tail, but when a message is divided into several pieces, chr(0) and chr(255) in 
fact are not exist in each fragment 

Original comment by kev...@gmail.com on 9 May 2011 at 10:47