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; }
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); }
public function onRun() { foreach ($this->loadPaths as $name => $path) { if (!class_exists($name, false) and !interface_exists($name, false)) { require $path; } } $this->loader->register(true); $rsa = new RSA(); $this->logger->info("[BigBrother] Generating keypair"); $rsa->setPrivateKeyFormat(CRYPT_RSA_PRIVATE_FORMAT_PKCS1); $rsa->setPublicKeyFormat(CRYPT_RSA_PUBLIC_FORMAT_PKCS1); $keys = $rsa->createKey(1024); $this->setResult($keys); }
public function run() { $this->registerClassLoader(); gc_enable(); error_reporting(-1); ini_set("display_errors", 1); ini_set("display_startup_errors", 1); set_error_handler([$this, "errorHandler"], E_ALL); register_shutdown_function([$this, "shutdownHandler"]); try { $socket = new SynapseSocket($this->getLogger(), $this->port, $this->interface); new ServerConnection($this, $socket); } catch (\Throwable $e) { $this->logger->logException($e); } }