Skip to content

Error socket error when sending message larger that 200kb #133

@alysdal

Description

@alysdal

Hi,

I'm trying to publish a 200 kb message to a topic, but i keep getting the socket error:

 PhpMqtt\Client\Exceptions\DataTransferException

  [65] Transferring data over socket failed: Sending data over the socket failed. Has it been closed?

  at vendor/php-mqtt/client/src/MqttClient.php:1147
    1143$result = @fwrite($this->socket, $data, $length);
    11441145if ($result === false || $result !== $length) {
    1146$this->logger->error('Sending data over the socket to the broker failed.');
  ➜ 1147throw new DataTransferException(
    1148▕                 DataTransferException::EXCEPTION_TX_DATA,
    1149'Sending data over the socket failed. Has it been closed?'
    1150▕             );
    1151▕         }

Splitting the message is not an option as this is used in an OTA update for a device that expects a single binary message.

Here is a code example to reproduce the issue:

$mqtt = new \PhpMqtt\Client\MqttClient('test.mosquitto.org', '1883');
// Create and configure the connection settings as required.
$connectionSettings = (new ConnectionSettings)
     ->setUsername(null)
     ->setPassword(null);

$mqtt->connect($connectionSettings, true);
$count = 1000*200; // 200 kilobytes
$mqtt->publish("topic", str_repeat('-', $count));

Any ideas how i might accomplish this or how we could solve this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions