Send a message to the socket.

@param mixed $msg

@return bool
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);
    }
1196600
public function warn($msg)
    {
        if ($this->iniGetBool('display_errors') === true) {
            $this->write((string)$msg, 'WARNING');
        }

        return $this;
    }
397318
def send_message(self, msg):
        

        if self.socket is not None:

            msg.version = self.PROTOCOL_VERSION
            serialized = msg.SerializeToString()
            data = struct.pack(">I", len(serialized)) + serialized

            #print("Sending message: %s" % msg)
            try:
                self.socket.send(data)
            except Exception as e:
                #self.state = "Disconnected"
                pass
1298526
public function handlesMessage(Message $msg)
    {
        $handledMsgCodes = [
            Message::MSG_CALL,
            Message::MSG_CANCEL,
            Message::MSG_REGISTER,
            Message::MSG_UNREGISTER,
            Message::MSG_YIELD,
            Message::MSG_INTERRUPT
        ];

        if (in_array($msg->getMsgCode(), $handledMsgCodes)) {
            return true;
        } elseif ($msg instanceof ErrorMessage && $msg->getErrorMsgCode() === Message::MSG_INVOCATION) {
            return true;
        } elseif ($msg instanceof ErrorMessage && $msg->getErrorMsgCode() === Message::MSG_INTERRUPT) {
            return true;
        } else {
            return false;
        }
    }
1144639
public function message($msg)
    {
        foreach ($this as $client) {
            try {
                $this->execute(
                    "sendtextmessage",
                    array("msg" => $msg, "target" => $client, "targetmode" => Teamspeak::TEXTMSG_CLIENT)
                );
            } catch (TeamSpeak3_Adapter_ServerQuery_Exception $e) {
                /* ERROR_client_invalid_id */
                if ($e->getCode() != 0x0200) {
                    throw $e;
                }
            }
        }
    }
125597
public function sendMessage(Message $message)
    {
        $this->currentId++;
        $messageData = $message->convertToRconData($this->currentId);
        $this->client->write($messageData);

        return $this->getResponseMessage();
    }
1370428
def socket_send(
        sock,
        msg,
        debug=False):
    
    if IS_PY2:
        sock.send(msg)
    else:
        sock.send(msg.encode())
619310
public function send(Message $message)
    {
        return $this->guzzleClient->post(
            $this->getApiUrl(),
            [
                'headers' => [
                    'Authorization' => sprintf('key=%s', $this->apiKey),
                    'Content-Type' => 'application/json'
                ],
                'body' => json_encode($message)
            ]
        );
    }
335981
private function onMessage($msg, $socket) {
        try {
            $payload = @json_decode($msg, true);
            if (!$payload) {
                $this->response($socket, ['error' => 403, 'message' => 'error request']);

                return;
            }
            $command = isset($payload['command']) ? $payload['command'] : 'status';
            $service = isset($payload['args']['service']) ? $payload['args']['service'] : '';
            switch ($command) {
                case 'stop':
                    if ($service) {
                        $rst = $this->stopService($service);
                        $this->response($socket, ['status' => $rst ? 'done' : 'fail']);
                    } else {
                        $this->response($socket, ['status' => 'done']);
                        $this->shutdown = true;
                        $this->rSignal  = SIGTERM;
                    }
                    break;
                case 'start':
                    if ($service) {
                        $rst = $this->startService($service);
                        $this->response($socket, ['status' => $rst ? 'done' : 'fail']);
                    } else {
                        $this->response($socket, ['status' => 'fail']);
                    }
                    break;
                case 'reload':
                    $rst = $this->reloadConfig(null, $service);
                    $this->response($socket, ['status' => $rst ? 'done' : 'fail']);
                    break;
                case 'ps':
                    if ($service) {
                        if (isset($this->services[ $service ])) {
                            $pids = isset($this->services[ $service ]['pids']) ? $this->services[ $service ]['pids'] : [];
                            $this->response($socket, [
                                'ps'   => [$service => $pids],
                                'ssid' => posix_getpid()
                            ]);
                        } else {
                            $this->response($socket, ['ps' => [], 'ssid' => posix_getpid()]);
                        }
                    } else {
                        $ps = [];
                        foreach ($this->services as $s => $ser) {
                            $ps[ $s ] = isset($ser['pids']) ? $ser['pids'] : [];
                        }
                        $this->response($socket, ['ps' => $ps, 'ssid' => posix_getpid()]);
                    }
                    break;
                case 'status':
                default:
                    if ($service) {
                        if (isset($this->services[ $service ])) {
                            $this->response($socket, [
                                'status' => $this->services[ $service ]['status'],
                                'detail' => $this->services[ $service ]
                            ]);
                        } else {
                            $this->response($socket, ['status' => 'unknown', 'detail' => []]);
                        }
                    } else {
                        $this->response($socket, ['status' => 'running', 'services' => $this->services]);
                    }
            }
        } catch (\Exception $e) {
            $this->response($socket, ['error' => 500, 'msg' => $e->getMessage()]);
        }
    }
1036167
public function pack($msg)
    {
        if (!$msg instanceof Message) {
            trigger_error("Given parameter is not a message instance.",
                          E_USER_ERROR);
            return;
        }

        // Set value using serialzed message.
        $this->value = $msg->serializeToString();

        // Set type url.
        $pool = \Google\Protobuf\Internal\DescriptorPool::getGeneratedPool();
        $desc = $pool->getDescriptorByClassName(get_class($msg));
        $fully_qualifed_name = $desc->getFullName();
        $this->type_url = GPBUtil::TYPE_URL_PREFIX.substr(
            $fully_qualifed_name, 1, strlen($fully_qualifed_name));
    }
342505
public function execute(AMQPMessage $msg)
    {
        echo str_repeat('-', 60).PHP_EOL;

        echo '[RECV ' . date('c') . ']' . PHP_EOL .'<content>' .
            PHP_EOL . $msg->body . PHP_EOL . '</content>'.PHP_EOL.PHP_EOL;

        echo "*" . ' INFO ' . PHP_EOL;
        foreach ($msg->{'delivery_info'} as $key => $value) {
            if (is_scalar($value)) {
                echo "** " . $key . ' = ' . $value . PHP_EOL;
            }
        }
        echo "*" . ' PROPERTIES ' . PHP_EOL;
        foreach ($msg->get_properties() as $property => $value) {
            if (is_scalar($value)) {
                echo "** " . $property . ' = ' . $value . PHP_EOL;
            }
        }
    }
74070
public function send(array $data)
    {
        $text = self::sanitizeText($data['text']);
        $to   = preg_replace("/[(,),\-,\s]/", "", $data['to']);
        $from = preg_replace("/[(,),\-,\s]/", "", $data['from']);

        $this->client->messages->create($to, ['from' => $from, 'body' => $text]);

        return true;
    }
1302409
public function sendMessage(Message $message) {
        if ($this->isDisabled()) {
            return false;
        }

        $users = $message->getMyDestionationUsers($this->container);
        $sentCount = 0;
        foreach($users as $user) {
            //if($user->getId() != $message->getFromUser()->getId()){
            $sentCount += $this->sendMessageToUser($message, $user);
            //}
        }
        return $sentCount;
    }
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;
    }
491420
public static function send($message)
    {
        if (is_array($message)) {
            $message = new Message($message);
        }

        return static::getMailer()->send($message->getOriginal());
    }
335137
def send(self, msg):
        
        with self._pub_lock:
            self.publish.send_string(msg)
        return self
887827
protected function send($s)
    {
        if (!$this->socket) {
            $this->createSocket();
        }

        if (!$this->socket) {
            return false;
        }

        $written = 0;
        while ($s != '') {
            $written = $this->write($s);
            if ($written === false) {
                throw new \Plop\Exception('Connection lost');
            }
            $s = (string) substr($s, $written);
        }
        return true;
    }