Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onmessage being called multiple times #31

Open
GoogleCodeExporter opened this issue Apr 23, 2015 · 4 comments
Open

onmessage being called multiple times #31

GoogleCodeExporter opened this issue Apr 23, 2015 · 4 comments

Comments

@GoogleCodeExporter
Copy link

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
Copy link
Author

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
Copy link
Author

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
Copy link
Author

[deleted comment]

@GoogleCodeExporter
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant