Exemplo n.º 1
0
 /**
  * Execute the action.
  * @param array command line parameters specific for this command
  */
 public function run($args)
 {
     // set some variables
     //$host = "127.0.0.1";
     $host = "192.168.1.2";
     $port = 4122;
     //$icounter=0;
     /*
     // don't timeout!
     set_time_limit(0);
     // create socket
     $socket = socket_create(AF_INET, SOCK_STREAM, 0) or die("Could not create
     socket\n");
     // bind socket to port
     $result = socket_bind($socket, $host, $port) or die("Could not bind to
     socket\n");
     
     $icounter=0;
     
     while ($icounter < 3)
     {
     // start listening for connections
     $result = socket_listen($socket, 3) or die("Could not set up socket
     listener\n");
     // accept incoming connections
     // spawn another socket to handle communication
     $spawn = socket_accept($socket) or die("Could not accept incoming
     connection\n");
     
     // read client input
     $input = socket_read($spawn, 1024) or die("Could not read input\n");
     
     $handle = fopen("d:\\resource.txt", "a+");
     fwrite($handle,$input);
     
     /*
     $imei_ary = array();
     foreach (str_split($input) as $chr)
     $imei_ary[] = sprintf("%c", ord($chr));
     */
     /*
     $input = '#RD000001004361412111849153955.6583N03253.2103E000.04500000A00113971Da7LARNU8H40GT20KHU0W000296B15CE086';
     echo $input;
     */
     // Create the server
     try {
         $server = new Socket();
     } catch (SocketException $e) {
         echo "Can't start server, " . $e->getMessage();
     }
     // Start the listen loop
     try {
         $server->listen($host, $port);
     } catch (SocketException $e) {
         echo "Can't listen, " . $e->getMessage();
     }
     /*
     $input = '#SE00000100454355543020162426015';
     */
 }
Exemplo n.º 2
0
 /**
  * Create an Instance of a Server rearing to go.
  *
  * @param string $address An IPv4, IPv6, or Unix socket address
  * @param int    $port
  * @param int    $timeout Seconds to wait on a socket before timing it out
  */
 public function __construct($address, $port = 0, $timeout = null)
 {
     set_time_limit(0);
     $this->address = $address;
     $this->port = $port;
     $this->timeout = $timeout;
     switch (true) {
         case filter_var($address, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4):
             $this->domain = AF_INET;
             break;
         case filter_var($address, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6):
             $this->domain = AF_INET6;
             break;
         default:
             $this->domain = AF_UNIX;
     }
     $this->masterSocket = Socket::create($this->domain, SOCK_STREAM, 0);
     $this->masterSocket->bind($this->address, $this->port);
     $this->masterSocket->getSockName($this->address, $this->port);
     $this->masterSocket->listen();
 }
Exemplo n.º 3
0
 /**
  * Listens on the main socket
  *
  * @return void
  */
 public function listen()
 {
     $this->socket->listen();
     $this->resources[$this->socket->getResourceId()] = $this->socket->getResource();
 }