當前位置: 首頁>>代碼示例>>PHP>>正文


PHP socket_send函數代碼示例

本文整理匯總了PHP中socket_send函數的典型用法代碼示例。如果您正苦於以下問題:PHP socket_send函數的具體用法?PHP socket_send怎麽用?PHP socket_send使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了socket_send函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: send

function send()
{
    if (!($sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP))) {
        $errorcode = socket_last_error();
        $errormsg = socket_strerror($errorcode);
        die("Couldn't create socket: [{$errorcode}] {$errormsg} \n");
    }
    echo "Socket created";
    if (!socket_connect($sock, '192.168.0.17', 9000)) {
        $errorcode = socket_last_error();
        $errormsg = socket_strerror($errorcode);
        die("Could not connect: [{$errorcode}] {$errormsg} \n");
    }
    echo "Connection established \n";
    $msg = "Hello";
    //Send the message to the server
    if (!socket_send($sock, $msg, strlen($msg), 0)) {
        $errorcode = socket_last_error();
        $errormsg = socket_strerror($errorcode);
        die("Could not send data: [{$errorcode}] {$errormsg} \n");
    }
    echo "Message send successfully \n";
    //Now receive reply from server
    if (socket_recv($sock, $buf, 2045, MSG_WAITALL) === FALSE) {
        $errorcode = socket_last_error();
        $errormsg = socket_strerror($errorcode);
        die("Could not receive data: [{$errorcode}] {$errormsg} \n");
    }
    //print the received message
    $visual = $buf;
    socket_close($sock);
}
開發者ID:rafafloripa,項目名稱:project_fall_semester_2015,代碼行數:32,代碼來源:test.php

示例2: send_data

function send_data($_remote_ip, $_remote_port, $_message)
{
    if (preg_match('/^(([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]).){3}([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/', $_remote_ip)) {
        //  echo 'IP ist gültig.';
    } else {
        $_remote_ip = gethostbyname($_remote_ip);
    }
    if (!($sock = socket_create(AF_INET, SOCK_STREAM, 0))) {
        $errorcode = socket_last_error();
        $errormsg = socket_strerror($errorcode);
        die("Couldn't create socket: [{$errorcode}] {$errormsg} \n");
        $log_update = mysql_query("INSERT INTO `log`(`message`) VALUES ('" . $errormsg . "')");
    }
    echo "Socket created \n";
    //Connect socket to remote server
    if (!socket_connect($sock, $_remote_ip, $_remote_port)) {
        $errorcode = socket_last_error();
        $errormsg = socket_strerror($errorcode);
        die("Could not connect: [{$errorcode}] {$errormsg} \n");
        $log_update = mysql_query("INSERT INTO `log`(`message`) VALUES ('" . $errormsg . "')");
    }
    echo "Connection established \n";
    //Send the message to the server
    if (!socket_send($sock, $_message, strlen($_message), 0)) {
        $errorcode = socket_last_error();
        $errormsg = socket_strerror($errorcode);
        die("Could not send data: [{$errorcode}] {$errormsg} \n");
        $log_update = mysql_query("INSERT INTO `log`(`message`) VALUES ('" . $errormsg . "')");
    }
    echo "Message send successfully \n";
    //$log_update = mysql_query("INSERT INTO `log`(`message`) VALUES ('".$_remote_ip."')");
}
開發者ID:RBEGamer,項目名稱:SmartLightHub,代碼行數:32,代碼來源:toggle_scene.php

示例3: sendaprs

function sendaprs($call, $lat, $lon, $desc, $ts)
{
    global $aprs_server;
    global $msg;
    $s = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
    socket_connect($s, $aprs_server, 14580);
    $N = 'N';
    if ($lat < 0) {
        $lat = -$lat;
        $N = 'S';
    }
    $E = 'E';
    if ($lon < 0) {
        $lon = -$lon;
        $E = 'W';
    }
    $msg = $call . ">WEB2NT:!";
    $msg = $msg . sprintf("%02d%05.2f%s%s", floor($lat), ($lat - floor($lat)) * 60, $N, substr($ts, 0, 1));
    $msg = $msg . sprintf("%03d%05.2f%s%s", floor($lon), ($lon - floor($lon)) * 60, $E, substr($ts, 1, 1));
    $msg = $msg . sprintf("%s%s", $desc, "\r\n");
    //	echo $msg;
    //	echo "<p>";
    socket_send($s, $msg, strlen($msg), 0);
    $msg = date("Y-m-d H:i:s ") . $msg;
}
開發者ID:bg6cq,項目名稱:aprs,代碼行數:25,代碼來源:index.php

示例4: coop_send

function coop_send($message)
{
    if (!($sock = socket_create(AF_INET, SOCK_STREAM, 0))) {
        $errorcode = socket_last_error();
        $errormsg = socket_strerror($errorcode);
        die("Couldn't create socket: [{$errorcode}] {$errormsg} \n");
    }
    //Connect socket to remote server
    if (!socket_connect($sock, COOPSERVER, COOPPORT)) {
        $errorcode = socket_last_error();
        $errormsg = socket_strerror($errorcode);
        die("Could not connect: [{$errorcode}] {$errormsg} \n");
    }
    //Send the message to the server
    if (!socket_send($sock, $message, strlen($message), 0)) {
        $errorcode = socket_last_error();
        $errormsg = socket_strerror($errorcode);
        die("Could not send data: [{$errorcode}] {$errormsg} \n");
    }
    $buf = 'my buffer';
    if (false !== ($bytes = socket_recv($sock, $buf, 1024, 0))) {
        echo "Read {$bytes} bytes of socket_recv(). close socket ...";
    } else {
        echo "socket_recv() error; Reason: " . socket_strerror(socket_last_error($socket)) . "\n";
    }
    socket_close($sock);
    return $buf;
}
開發者ID:gludie,項目名稱:CoopControl,代碼行數:28,代碼來源:coopclient.php

示例5: send

 /**
  * 發送數據
  * @param string $data
  * @return bool | int
  */
 function send($data)
 {
     $length = strlen($data);
     $written = 0;
     $t1 = microtime(true);
     //總超時,for循環中計時
     while ($written < $length) {
         $n = socket_send($this->sock, substr($data, $written), $length - $written, null);
         //超過總時間
         if (microtime(true) > $this->timeout_send + $t1) {
             return false;
         }
         if ($n === false) {
             $errno = socket_last_error($this->sock);
             //判斷錯誤信息,EAGAIN EINTR,重寫一次
             if ($errno == 11 or $errno == 4) {
                 continue;
             } else {
                 return false;
             }
         }
         $written += $n;
     }
     return $written;
 }
開發者ID:jasonshaw,項目名稱:framework-1,代碼行數:30,代碼來源:TCP.php

示例6: sendCommandToRPi

function sendCommandToRPi($command)
{
    if (!($sock = socket_create(AF_INET, SOCK_STREAM, 0))) {
        $errorcode = socket_last_error();
        $errormsg = socket_strerror($errorcode);
        die("Couldn't create socket: [{$errorcode}] {$errormsg} \n");
    }
    //Connect socket to remote server
    try {
        if (!socket_connect($sock, '172.17.10.71', 1111)) {
            $errorcode = socket_last_error();
            $errormsg = socket_strerror($errorcode);
            echo $errormsg;
            return False;
        }
    } catch (Exception $e) {
    }
    //Send the message to the server
    if (!socket_send($sock, $command, strlen($command), 0)) {
        $errorcode = socket_last_error();
        $errormsg = socket_strerror($errorcode);
        return False;
    }
    return true;
}
開發者ID:GauthLin,項目名稱:MaMaisonnette,代碼行數:25,代碼來源:functions.php

示例7: negotiate

function negotiate($socket)
{
    socket_recv($socket, $buffer, 1024, 0);
    for ($chr = 0; $chr < strlen($buffer); $chr++) {
        if ($buffer[$chr] == chr(255)) {
            $send = isset($send) ? $send . $buffer[$chr] : $buffer[$chr];
            $chr++;
            if (in_array($buffer[$chr], array(chr(251), chr(252)))) {
                $send .= chr(254);
            }
            if (in_array($buffer[$chr], array(chr(253), chr(254)))) {
                $send .= chr(252);
            }
            $chr++;
            $send .= $buffer[$chr];
        } else {
            break;
        }
    }
    if (isset($send)) {
        socket_send($socket, $send, strlen($send), 0);
    }
    if ($chr - 1 < strlen($buffer)) {
        return substr($buffer, $chr);
    }
}
開發者ID:sean-perryman,項目名稱:home-control,代碼行數:26,代碼來源:php-test.php

示例8: init

 public function init()
 {
     if (!($sock = socket_create(AF_INET, SOCK_STREAM, 0))) {
         $errorcode = socket_last_error();
         $errormsg = socket_strerror($errorcode);
         die("Couldn't create socket: [{$errorcode}] {$errormsg} \n");
     }
     echo "Socket created \n";
     //Connect socket to remote server
     if (!socket_connect($sock, self::ADDRESS, self::PORT)) {
         $errorcode = socket_last_error();
         $errormsg = socket_strerror($errorcode);
         die("Could not connect: [{$errorcode}] {$errormsg} \n");
     }
     echo "Connection established \n";
     $message = json_encode(['message' => 'Alright!']);
     //Send the message to the server
     if (!socket_send($sock, $message, strlen($message), 0)) {
         $errorcode = socket_last_error();
         $errormsg = socket_strerror($errorcode);
         die("Could not send data: [{$errorcode}] {$errormsg} \n");
     }
     echo "Message send successfully \n";
     //Now receive reply from server
     if (socket_recv($sock, $buf, 2045, MSG_WAITALL) === FALSE) {
         $errorcode = socket_last_error();
         $errormsg = socket_strerror($errorcode);
         die("Could not receive data: [{$errorcode}] {$errormsg} \n");
     }
     //print the received message
     socket_shutdown($sock);
     return $buf;
 }
開發者ID:LucasMaliszewski,項目名稱:SimpleAi,代碼行數:33,代碼來源:Listen.php

示例9: write

 /**
  * Writes data to the socket.
  *
  * @param  string  $string  String to send.
  * @param  integer  $flags  Send flags - php.net/socket_send
  *
  * @return  integer|boolean  Number of bytes written, False on error
  */
 public function write($string, $flags = null)
 {
     if ($flags !== null) {
         return socket_send($this->get_resource(), $string, strlen($string), $flags);
     }
     return socket_write($this->get_resource(), $string);
 }
開發者ID:prggmr,項目名稱:xpspl,代碼行數:15,代碼來源:connection.php

示例10: write

 /**
  * Writes to this peer.
  *
  * @param string $what What to write.
  *
  * @return integer
  */
 public function write($what)
 {
     $ret = null;
     if ($this->isConnected()) {
         $ret = @socket_send($this->socket, $what, strlen($what), 0);
     }
     return $ret;
 }
開發者ID:im286er,項目名稱:Ding,代碼行數:15,代碼來源:TcpPeer.php

示例11: dataIs

 protected final function dataIs(data\data $data)
 {
     $bytesWritten = socket_send($this->resource, $data, strlen($data), 0);
     if ($bytesWritten === false) {
         throw $this->exception();
     }
     return $this->numberOfBytesConsumedIs(new data\data\numberOfBytes($bytesWritten));
 }
開發者ID:estvoyage,項目名稱:net,代碼行數:8,代碼來源:socket.php

示例12: send_all

function send_all(&$socket, $snd)
{
    $to_send = strlen($snd) . ":" . $snd;
    if (@socket_send($socket, $to_send, strlen($to_send), 0)) {
        return true;
    }
    return false;
}
開發者ID:HeBD,項目名稱:DownloadDaemon,代碼行數:8,代碼來源:functions.inc.php

示例13: send

 public function send(ServerMessage\Crypt $message)
 {
     $message->prepend(ByteConverter::IntSixteenBits($message->getLength()));
     if (!socket_send($this->socket, $message, strlen($message), 0)) {
         $this->error();
     }
     return $this;
 }
開發者ID:mszula,項目名稱:php-newcamd,代碼行數:8,代碼來源:Socket.php

示例14: write

 public function write($buffer, $length)
 {
     $bytesWritten = socket_send($this->socket, $buffer, $length, 0);
     if ($bytesWritten === false) {
         $bytesWritten = -1;
     }
     return $bytesWritten;
 }
開發者ID:Athorcis,項目名稱:athorrent-frontend,代碼行數:8,代碼來源:LocalClientSocket.php

示例15: send

function send($message)
{
    global $sock;
    if (!socket_send($sock, $message, strlen($message), 0)) {
        $errorcode = socket_last_error();
        $errormsg = socket_strerror($errorcode);
        echo "Could not send data: [{$errorcode}] {$errormsg} \n";
    }
}
開發者ID:AlgoTelecomNancy,項目名稱:SpaceMission,代碼行數:9,代碼來源:test.php


注:本文中的socket_send函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。