Skip to content

Error receiving bytes messages #28

@ghost

Description

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions