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

Error receiving bytes messages #28

Open
ghost opened this issue Aug 7, 2014 · 2 comments
Open

Error receiving bytes messages #28

ghost opened this issue Aug 7, 2014 · 2 comments

Comments

@ghost
Copy link

ghost commented Aug 7, 2014

I was having problems receiving bytes messages for use with googles / chobies protocolbuffers php implementation with this STOMP implementation. Sending to a Java client worked like a charm, but the return to PHP failed trying to deserialize the protocol buffer bytes.
When executing $msg = $con->readFrame, it truncated the bytes by doing a trim on the message body removing all whitespace. The solution is the following new function for Stomp.php, whatch this line only stripping "\x00" instead of all whitespace :

$frame = new StompFrame($command, $headers, trim($body, "\x00"));

/**
* Read response frame from server for binairy messages
*
* @return StompFrame False when no frame to read
*/
public function readFrameBinairy ()
{
if (!$this->hasFrameToRead()) {
return false;
}
$rb = 1024;
$data = '';
$end = false;
do {
$read = fread($this->_socket, $rb);
if ($read === false) {
$this->_reconnect();
return $this->readFrame();
}
$data .= $read;
if (strpos($data, "\x00") !== false) {
$end = true;
$data = rtrim($data, "\n");
}
$len = strlen($data);
} while ($len < 2 || $end == false);
list ($header, $body) = explode("\n\n", $data, 2);
$header = explode("\n", $header);
$headers = array();
$command = null;
foreach ($header as $v) {
if (isset($command)) {
list ($name, $value) = explode(':', $v, 2);
$headers[$name] = $value;
} else {
$command = $v;
}
}
$frame = new StompFrame($command, $headers, trim($body, "\x00"));
if (isset($frame->headers['transformation']) && $frame->headers['transformation'] == 'jms-map-json') {
require_once 'Stomp/Map.php';
return new StompMessageMap($frame);
} else {
return $frame;
}
return $frame;
}

Thanks to my colleague Jan Grävell for his excelent PHP knowlledge.

@yanniboi
Copy link

I am having a similar problem. I cant vouch for the code above, but I am working with a feed that gzips the content of the messages. Then when the body is trimmed it breaks the gzip encoded strings. So it would be great if there was a way of telling it to not trim the body on some frames.

@jmglsn
Copy link

jmglsn commented Apr 12, 2016

@yanniboi @ghost please use the current version located at https://github.com/stomp-php/stomp-php

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

No branches or pull requests

2 participants