Esempio n. 1
0
 public function connect()
 {
     $this->socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
     if ($this->socket === false or !@socket_connect($this->socket, $this->interface, $this->port)) {
         $this->logger->critical("Synapse Client can't connect {$this->interface}:{$this->port}");
         $this->logger->error("Socket error: " . socket_strerror(socket_last_error()));
         return false;
     }
     $this->logger->info("Synapse has connected to {$this->interface}:{$this->port}");
     socket_set_nonblock($this->socket);
     return true;
 }
Esempio n. 2
0
 public function __construct(\ThreadedLogger $logger, $port = 19132, $interface = "0.0.0.0")
 {
     $this->socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
     //socket_set_option($this->socket, SOL_SOCKET, SO_BROADCAST, 1); //Allow sending broadcast messages
     if (@socket_bind($this->socket, $interface, $port) === true) {
         socket_set_option($this->socket, SOL_SOCKET, SO_REUSEADDR, 0);
         $this->setSendBuffer(1024 * 1024 * 8)->setRecvBuffer(1024 * 1024 * 8);
     } else {
         $logger->critical("**** FAILED TO BIND TO " . $interface . ":" . $port . "!", true, true, 0);
         $logger->critical("Perhaps a server is already running on that port?", true, true, 0);
         exit(1);
     }
     socket_set_nonblock($this->socket);
 }