当前位置: 首页>>代码示例>>PHP>>正文


PHP socket_close函数代码示例

本文整理汇总了PHP中socket_close函数的典型用法代码示例。如果您正苦于以下问题:PHP socket_close函数的具体用法?PHP socket_close怎么用?PHP socket_close使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了socket_close函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: start

 public function start()
 {
     $host = $this->host;
     $port = $this->port;
     echo "app can be acessed from ws://{$host}:{$port}\n";
     $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
     if ($socket === false) {
         $this->logLastError($socket, "1");
     }
     if (socket_bind($socket, $host, $port) === false) {
         $this->logLastError($socket, "2");
     }
     if (socket_listen($socket, 5) === false) {
         $this->logLastError($socket, "3");
     }
     $this->setServerSocket($socket);
     $serverSocket = $this->getServerSocket();
     do {
         $sockets = $this->getSockets();
         //Set up a blocking call to socket_select
         $write = null;
         $except = null;
         $tv_sec = 5;
         if (socket_select($sockets, $write, $except, $tv_sec) < 1) {
             continue;
         } else {
             $this->setSockets($sockets);
         }
         //Handle new Connections
         if ($this->hasSocket($serverSocket)) {
             $clientSocket = socket_accept($serverSocket);
             if ($clientSocket === false) {
                 $this->logLastError($serverSocket, "4");
             } else {
                 $this->setClientSocket($clientSocket);
                 $response = "HTTP/1.1 101 Switching Protocols";
                 $this->respond($clientSocket, $response);
             }
         }
         //Handle Input
         foreach ($this->getClientSockets() as $clientSocket) {
             if ($this->hasSocket($clientSocket)) {
                 $message = socket_read($clientSocket, 2048, PHP_NORMAL_READ);
                 if ($message === false) {
                     $this->logLastError($clientSocket, "5");
                     $this->removeSocket($clientSocket);
                     socket_close($clientSocket);
                     break;
                 } else {
                     $message = trim($message);
                     if (!empty($message)) {
                         $response = $this->trigger("message", ["{$message}"]);
                         $this->respond($clientSocket, $response);
                     }
                 }
             }
         }
     } while (true);
     socket_close($serverSocket);
 }
开发者ID:wispira,项目名称:framework,代码行数:60,代码来源:Server.php

示例2: print_sock_err

function print_sock_err($sock, $type)
{
    $errno = socket_last_error($sock);
    $errmsg = socket_strerror($errno);
    echo "{$type} ERROR:{$errno} - {$errmsg}" . PHP_EOL;
    socket_close($sock);
}
开发者ID:luoqing,项目名称:simpleSocketCode,代码行数:7,代码来源:php-cli.php

示例3: hg_sendCmd

function hg_sendCmd($cmd, $ip, $port)
{
    $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
    if ($socket < 0) {
        return false;
    }
    $result = socket_connect($socket, $ip, $port);
    if ($result < 0) {
        return false;
    }
    if (!isset($cmd['charset'])) {
        $cmd['charset'] = '';
    }
    $str = json_encode($cmd);
    //echo ($str);
    //$str = base64_encode($str);
    socket_write($socket, $str, strlen($str));
    $data = '';
    while ($out = socket_read($socket, 256)) {
        $data .= $out;
        if (strlen($out) < 256) {
            break;
        }
    }
    socket_close($socket);
    //$data = base64_decode($data);
    return $data;
}
开发者ID:h3len,项目名称:Project,代码行数:28,代码来源:functions.php

示例4: ircReport

function ircReport($stuff)
{
    $sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
    socket_connect($sock, Settings::pluginGet("host"), Settings::pluginGet("port"));
    socket_write($sock, $stuff . "\n");
    socket_close($sock);
}
开发者ID:RoadrunnerWMC,项目名称:ABXD-plugins,代码行数:7,代码来源:init.php

示例5: close

 public function close()
 {
     if ($this->isOpened()) {
         socket_close($this->socket);
     }
     $this->socket = NULL;
 }
开发者ID:aircross,项目名称:esc-pos,代码行数:7,代码来源:Network.php

示例6: sendsock

function sendsock($in)
{
    global $config;
    $service_port = $config['sockport'];
    $address = $config['sockhost'];
    if (!function_exists("socket_create")) {
        error_log(date("y-m-d H:i:s") . " 未启用socket模块\n", 3, "error.log");
        return null;
    }
    $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
    if ($socket === false) {
        error_log(date("y-m-d H:i:s") . "socket_create() failed, reason: " . socket_strerror(socket_last_error()) . "\n", 3, "error.log");
        return null;
    }
    $result = socket_connect($socket, $address, $service_port);
    if ($result === false) {
        error_log(date("y-m-d H:i:s") . "socket_connect() failed.\nReason: ({$result}) " . socket_strerror(socket_last_error($socket)) . "\n", 3, "error.log");
        return null;
    }
    socket_write($socket, $in, strlen($in));
    $result = socket_read($socket, 8192);
    $arr = unpack("C*", $result);
    socket_close($socket);
    return $arr;
}
开发者ID:707wk,项目名称:mechanical_parking_system,代码行数:25,代码来源:index.php

示例7: sendUSD

function sendUSD($text, $pass_server = '000000')
{
    $address = gethostbyname('127.0.0.1');
    //IP Адрес вашего компьютера
    $service_port = 8000;
    //Порт
    //$pass_server='000000'; //Пароль
    $phone = preg_replace('/^\\+/', '', $phone);
    $socket = socket_create(AF_INET, SOCK_STREAM, 0);
    if ($socket < 0) {
        echo "socket create failed reason: " . socket_strerror($socket) . "\n";
    }
    $result = socket_connect($socket, $address, $service_port);
    if ($result < 0) {
        echo "socket connect failed.\nReason: ({$result}) " . socket_strerror($result) . "\n";
    }
    $text = iconv("UTF-8", "Windows-1251", $text);
    $in = base64_encode($pass_server . "#CMD#[USSD]" . $text);
    //Пример отправки смс
    //$in = base64_encode($pass_server."#CMD#[USSD]*102#"); //Пример запроса USSD команды
    $out = '';
    socket_write($socket, $in, strlen($in));
    //echo "Response:\n\n";
    $res = '';
    while ($out = socket_read($socket, 2048)) {
        $res .= $out;
    }
    socket_close($socket);
    $res = iconv("Windows-1251", "UTF-8", $res);
    if (preg_match('/USSD-RESPONSE\\[.+?\\]:(.+)/is', $res, $m)) {
        $res = $m[1];
    }
    return $res;
}
开发者ID:cdkisa,项目名称:majordomo,代码行数:34,代码来源:smsgw.php

示例8: close

 public function close()
 {
     if ($this->socket) {
         socket_close($this->socket);
         $this->socket = null;
     }
 }
开发者ID:agolomazov,项目名称:client,代码行数:7,代码来源:SocketConnection.php

示例9: get_peers_blocking

 private function get_peers_blocking($info_hash, $host = "router.bittorrent.com", $port = 6881)
 {
     //create a UDP socket to send commands through
     $socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
     //Create Command Packet
     $packet = bencode::encode(array("id" => $this->get_unique_node_id(), "info_hash" => hex2bin($info_hash)), array("q" => "get_peers", "t" => $this->unique_id(), "y" => "q"));
     socket_sendto($socket, $packet, strlen($packet), 0, $host, $port);
     //set timeout
     $timeout = array('sec' => 5, 'usec' => 0);
     socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, $timeout);
     $time = time();
     //recieve data
     try {
         socket_recvfrom($socket, $buf, 12000, 0, $host, $port);
     } catch (Exception $e) {
         echo "Error";
         return FALSE;
     }
     //have to manually do the timeout, cant seem to get info from this socket
     if (time() - $time >= 4) {
         socket_close($socket);
         return FALSE;
     }
     //close socket so bad shit don't happen
     socket_close($socket);
     return nodeExtract::return_nodes(bencode::decode($buf));
 }
开发者ID:sharayuS,项目名称:PHP-K-DHT,代码行数:27,代码来源:dht.class.php

示例10: search

 public function search($st = 'ssdp:all', $mx = 2, $man = 'ssdp:discover', $from = null, $port = null, $sockTimout = '2')
 {
     $request = 'M-SEARCH * HTTP/1.1' . "\r\n";
     $request .= 'HOST: 239.255.255.250:1900' . "\r\n";
     $request .= 'MAN: "' . $man . '"' . "\r\n";
     $request .= 'MX: ' . $mx . '' . "\r\n";
     $request .= 'ST: ' . $st . '' . "\r\n";
     $request .= 'USER-AGENT: ' . $this->user_agent . "\r\n";
     $request .= "\r\n";
     $socket = socket_create(AF_INET, SOCK_DGRAM, 0);
     socket_set_option($socket, SOL_SOCKET, SO_BROADCAST, true);
     socket_sendto($socket, $request, strlen($request), 0, '239.255.255.250', 1900);
     socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array('sec' => $sockTimout, 'usec' => '0'));
     $response = array();
     do {
         $buf = null;
         socket_recvfrom($socket, $buf, 1024, MSG_WAITALL, $from, $port);
         if (!is_null($buf)) {
             $data = $this->parseSearchResponse($buf);
             $response[$data['usn']] = $data;
         }
     } while (!is_null($buf));
     socket_close($socket);
     return $response;
 }
开发者ID:T-REX-XP,项目名称:UPnP,代码行数:25,代码来源:Core.php

示例11: disconnect

 protected function disconnect()
 {
     if (!$this->isAvailable()) {
         return;
     }
     socket_close($this->socket);
 }
开发者ID:seytar,项目名称:psx,代码行数:7,代码来源:LogCasterHandler.php

示例12: _tcp_send_request

 private static function _tcp_send_request($socket_write_json = null)
 {
     $sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
     if (false === $sock) {
         echo "sock create error!\n";
     }
     $address = Config::get("kgi.kgi_mid_server_ip");
     $port = Config::get("kgi.kgi_mid_server_port");
     try {
         $result = socket_connect($sock, $address, $port);
         if ($result === false) {
             echo "socket_connect() failed.\nReason: ({$result}) " . socket_strerror(socket_last_error($sock)) . "\n";
             exit;
             die;
         }
         socket_write($sock, $socket_write_json, strlen($socket_write_json));
         while ($out_str = socket_read($sock, 2048)) {
             //                echo "revice result\n";
             //                echo $out_str . "\n";
             $json_data = json_decode($out_str);
             break;
         }
         socket_close($sock);
     } catch (\ErrorException $e) {
         //echo $e->getMessage() . "\n";
     }
 }
开发者ID:buty,项目名称:gmf_trade_server,代码行数:27,代码来源:KgiClass.php

示例13: close

 /**
  * Closes the socket
  */
 public function close()
 {
     if ($this->socket && is_resource($this->socket)) {
         socket_close($this->socket);
     }
     $this->socket = null;
 }
开发者ID:vend,项目名称:statsd,代码行数:10,代码来源:Socket.php

示例14: udp

 public function udp()
 {
     set_time_limit(0);
     $ip = '127.0.0.1';
     $port = 9527;
     $socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
     socket_bind($socket, $ip, $port);
     $mem = init_mem();
     if ($mem == false) {
         return;
     }
     while (true) {
         socket_recvfrom($socket, $content, 1024, 0, $ip, $port);
         if (empty($content)) {
             continue;
         }
         //$this->log_data($content);
         $minute = (int) date("i");
         $datagram = $mem->get('datagram');
         if (empty($datagram)) {
             $datagram = array();
         }
         $datagram[$minute][] = $content;
         $mem->set('datagram', $datagram);
     }
     socket_close($socket);
     $mem->close();
 }
开发者ID:webdes83,项目名称:codeigniter-demos,代码行数:28,代码来源:server.php

示例15: testServer

 public function testServer()
 {
     $pid = pcntl_fork();
     if ($pid == 0) {
         socket_close($this->input[0]);
         socket_close($this->output[0]);
         $input = new \PHPixie\Illusion\Socket($this->input[1]);
         $output = new \PHPixie\Illusion\Socket($this->output[1]);
         $server = new \PHPixie\Illusion\Server(4747, 'localhost', $input, $output);
         $server->run();
     } else {
         socket_close($this->input[1]);
         socket_close($this->output[1]);
         $input = new \PHPixie\Illusion\Socket($this->input[0]);
         $output = new \PHPixie\Illusion\Socket($this->output[0]);
         $message = array('action' => 'route', 'method' => 'GET', 'headers' => array('Content-Type: text/plain'), 'path' => '/hello', 'response' => 'world');
         $input->write($message);
         $url = 'http://localhost:4747/hello';
         $response = $output->read(true);
         $this->assertEquals(array(array('url' => $url)), $response);
         $contents = file_get_contents($url);
         $this->assertEquals('world', $contents);
         $input->write(array('action' => 'stop'));
         sleep(2);
     }
 }
开发者ID:phpixie,项目名称:illusion,代码行数:26,代码来源:ServerTest.php


注:本文中的socket_close函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。