Sends a Message over this transport

@param Message $message

@return int the number of UDP packets sent
516523
public function send(Message $message)
    {
        $rawMessage = $this->getMessageEncoder()->encode($message);

        // test if we need to split the message to multiple chunks
        // chunkSize == 0 allows for an unlimited packet-size, and therefore
        // disables chunking
        if ($this->chunkSize && strlen($rawMessage) > $this->chunkSize) {
            return $this->sendMessageInChunks($rawMessage);
        }

        // send message in one packet
        $this->write($rawMessage);

        return 1;
    }
957943
protected function send($msg)
    {
        $msg .= PHP_EOL;

        return $this->socket->write($msg, strlen($msg));
    }
189308
static public function calculateForMessage(Message $message)
    {
        $dto = $message->toDTO();

        if (empty($dto["payload"]))
            return 0;

        // message fee is 0.05 (current fee factor) multiplied
        // by the count of *started* 31 characters chunks.
        $chunks = floor((strlen($dto["payload"]) / 2) / 32);
        return Fee::FEE_FACTOR * ($chunks + 1);
    }
457030
final public function send($message)
    {

        $response = $this->client()->{$this->config->getRequestMethod()}($this->config->getMessageUri(), array_merge(
                $this->config->getProviderConfig(), [
                    'command' => 'send',
                    'to' => $this->recipient,
                    'message' => $message,
                ])
        );

        return $this->getResponse($response);
    }
1226122
public static function padMessage($message)
    {
        $messageLen = strlen($message);
        $padLen = self::MAX_MESSAGE_LENGTH - $messageLen;

        return pack('n*', $padLen).str_pad($message, $padLen + $messageLen, chr(0), STR_PAD_LEFT);
    }
165140
protected function sendSwiftMessage($message)
    {
        if ($this->events) {
            $this->events->dispatch('mailer.sending', array($message));
        }

        if (! $this->pretending) {
            try {
                $this->swift->send($message, $this->failedRecipients);
            }
            finally {
                $this->swift->getTransport()->stop();
            }
        }

        // In the pretending mode.
        else if (isset($this->logger)) {
            $this->logMessage($message);
        }
    }
1347290
protected function sendSwiftMessage($message)
	{
		if ($this->events)
		{
			$this->events->fire('mailer.sending', array($message));
		}

		if ( ! $this->pretending)
		{
			return $this->swift->send($message, $this->failedRecipients);
		}
		elseif (isset($this->logger))
		{
			$this->logMessage($message);
		}
	}
243465
public function send(Message $message)
    {

        if (!$this->serverApiKey) {
            throw new Exception("Server API Key not set", Exception::ILLEGAL_API_KEY);
        }

        //GCM response: Number of messages on bulk (1001) exceeds maximum allowed (1000)
        if (count($message->getRegistrationIds()) > 1000) {
            throw new Exception(
                "Malformed request: Registration Ids exceed the GCM imposed limit of 1000",
                Exception::MALFORMED_REQUEST
            );
        }

        $rawData = $this->formMessageData($message);
        $this->validatePayloadSize($rawData, 'data', 4096);
        $this->validatePayloadSize($rawData, 'notification', 2048);
        $data = json_encode($rawData);

        $headers = array(
            'Authorization: key='.$this->serverApiKey,
            'Content-Type: application/json'
        );

        $ch = curl_init();

        curl_setopt($ch, CURLOPT_URL, $this->gcmUrl);

        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

        if ($this->caInfoPath !== false) {
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
            curl_setopt($ch, CURLOPT_CAINFO, $this->caInfoPath);
        } else {
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        }

        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

        $resultBody = curl_exec($ch);
        $resultHttpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

        curl_close($ch);

        switch ($resultHttpCode) {
            case "200":
                //All fine. Continue response processing.
                break;

            case "400":
                throw new Exception('Malformed request. '.$resultBody, Exception::MALFORMED_REQUEST);
                break;

            case "401":
                throw new Exception('Authentication Error. '.$resultBody, Exception::AUTHENTICATION_ERROR);
                break;

            default:
                //TODO: Retry-after
                throw new Exception("Unknown error. ".$resultBody, Exception::UNKNOWN_ERROR);
                break;
        }

        return new Response($message, $resultBody);
    }
874728
protected function sending(Message $message)
    {
        $phpMailer = new PHPMailer();
        $phpMailer->isSMTP();
        $phpMailer->SMTPDebug = $this->config[ 'debug' ];

        $host = $this->config[ 'host' ];

        if (is_array($this->config[ 'host' ])) {
            $host = implode(';', $this->config[ 'host' ]);
        }

        $phpMailer->Host = $host;
        $phpMailer->SMTPAuth = $this->config[ 'auth' ];
        $phpMailer->Username = $this->config[ 'username' ];
        $phpMailer->Password = $this->config[ 'password' ];
        $phpMailer->SMTPSecure = $this->config[ 'encryption' ];
        $phpMailer->Port = $this->config[ 'port' ];

        // Set from
        if (false !== ($from = $message->getFrom())) {
            $phpMailer->setFrom($from->getEmail(), $from->getName());
        }

        // Set recipient
        if (false !== ($to = $message->getTo())) {
            foreach ($to as $address) {
                if ($address instanceof Address) {
                    $phpMailer->addAddress($address->getEmail(), $address->getName());
                }
            }
        }

        // Set reply-to
        if (false !== ($replyTo = $message->getReplyTo())) {
            $phpMailer->addReplyTo($replyTo->getEmail(), $replyTo->getName());
        }

        // Set content-type
        if ($message->getContentType() === 'html') {
            $phpMailer->isHTML(true);
        }

        // Set subject, body & alt-body
        $phpMailer->Subject = $message->getSubject();
        $phpMailer->Body = $message->getBody();
        $phpMailer->AltBody = $message->getAltBody();

        if (false !== ($attachments = $message->getAttachments())) {
            foreach ($attachments as $filename => $attachment) {
                $phpMailer->addAttachment($attachment, $filename);
            }
        }

        if ( ! $phpMailer->send()) {
            $this->addError(100, $phpMailer->ErrorInfo);

            return false;
        }

        return true;
    }
531568
public function sendMessage(string $message) : ?Message 
    {
        $thread = $this->messageGroup();

        if ($thread === null) return null;

        return $thread->sendMessage($message);
    }
490655
public function send($msg): bool
    {
        // JSON encode message if supplied in array or object form
        if (is_array($msg) || is_object($msg)) {
            $msg = json_encode($msg);
        }

        // Ensure message is a string
        $msg = (string) $msg;

        // Check the message fits within the buffer
        if (strlen($msg) > $this->buffer) {
            throw new SocketCommunicationException('Tried to send data larger than buffer size of '.$this->buffer.' bytes. Recreate channel with a larger buffer to send this data');
        }

        // Pad the message to the buffer size
        $msg = str_pad($msg, $this->buffer, ' ');

        // Write the message to the socket
        return socket_write($this->socket, $msg, $this->buffer);
    }
654255
public function send(Message $message, array $emails): int
    {
        $this->connect(); // Establish or revive connection
        $this->command("RSET"); // Reset SMTP buffer

        $this->command(sprintf('MAIL FROM:<%1$s>', $message->sender()->email), null, 250); // Set mail from
        $count = 0;
        foreach ($emails as $email) {
            $this->write(sprintf('RCPT TO:<%1$s>', $email));
            $this->read();
            if ($this->lastResponseCode !== 250) {
                throw SMTPException::invalidRecipient(substr($this->lastResponse, 4));
            }

            $count++;
        }

        $messageMime = $message->compile();
        $messageMimeSize = strlen($messageMime);
        if ($this->options["size"] > 0 && $messageMimeSize > $this->options["size"]) {
            throw SMTPException::exceedsMaximumSize($messageMimeSize, $this->options["size"]);
        }

        $this->command("DATA", null, 354);
        $this->write($messageMime); // Write MIME
        $this->command(".", null, 250); // End DATA

        // Keep alive?
        if (!$this->keepAlive) {
            $this->write("QUIT"); // Send QUIT command
            //unset($this->stream);
            $this->stream = null;  // Close stream resource
        }

        return $count;
    }
359709
public function sendAndReceive(Message $message): Response
    {
        $xml = new \SimpleXMLElement('<?xml version="1.0" encoding="utf-8"?><wp:Notification xmlns:wp="WPNotification" />');
        $toast = $xml->addChild('wp:Toast');
        foreach ($message->getMessage() as $element => $value) {
            $toast->addChild($element, htmlspecialchars($value, ENT_XML1 | ENT_QUOTES));
        }
        $response = new ConnectionResponseImpl();

        $request = new Request('POST', $message->getIdentifier(), [], $xml->asXML());
        try {
            $clientResponse = $this->client->send($request);
            // check against headers? X-NotificationStatus / X-SubscriptionStatus / X-DeviceConnectionStatus
            // @see https://msdn.microsoft.com/en-us/library/windows/apps/ff941100(v=vs.105).aspx
            $response->setResponse($clientResponse->getBody()->getContents());
        } catch (RequestException $e) {
            $response->setErrorResponse($e);
        }

        return $response;
    }
403146
public function logMessage($message)
    {
        $this->logger->info(strip_tags($message));

        if ($this->sendToBrowser) {
            $this->sendMessageToBrowser($message);
        }

        if ($this->sendToCli) {
            $this->sendMessageToCli($message);
        }
    }
809404
public function queue(Message $message)
	{
		// Get the gateway for the certificate
		$gateway = $this->getGatewayForCertificate( $message->getCertificate() );

		// Queue the message
		return $gateway->queue($message);
	}
148324
public function send(Message $message)
    {
        $response = $this->guzzleClient->post('/messages', [
            'json' => [
                'originator' => $message->getOriginator(),
                'recipients' => $message->getRecipient(),
                'body'       => $message->getBody(),
            ],
            'http_errors' => false,
        ]);

        try {
            $document = JsonHelper::decode((string) $response->getBody());
        } catch (\RuntimeException $e) {
            throw new ApiRuntimeException('The MessageBird server did not return valid JSON.', [], $e);
        }

        if (isset($document['errors'])) {
            $errors = $document['errors'];
        } else {
            $errors = [];
        }

        $statusCode = (int) $response->getStatusCode();

        if (!in_array($statusCode, [200, 201, 204, 401, 404, 405, 422]) && !($statusCode >= 500 && $statusCode < 600)) {
            throw new ApiRuntimeException(sprintf('Unexpected MessageBird server behaviour (HTTP %d)', $statusCode), $errors);
        }

        if (!isset($document['recipients']['items'][0]['status'])) {
            $deliveryStatus = SendMessageResult::STATUS_NOT_SENT;
        } else {
            $deliveryStatus = $document['recipients']['items'][0]['status'];
        }

        return new SendMessageResult($deliveryStatus, $errors);
    }
1319865
public function send(OutgoingMessage $message)
    {
        foreach ($message->getTo() as $to)
        {
            $parameters = array(
                array(
                    'token' => $this->token,
                    'msisdn' => $to,
                    'message' => $message->composeMessage()
                )
            );

            $this->client->__call($this->service, $parameters);
        }

        return $message;
    }