public function __destruct() { if (true === $this->isConnected()) { socket_shutdown($this->socket); socket_close($this->socket); } }
function refresh_user($discord_id) { global $socket, $error; $so = socket_create(AF_UNIX, SOCK_DGRAM, 0); if ($so === false) { $msg = socket_strerror(socket_last_error()); $error = "Socket failed: {$msg}"; } else { $res = socket_connect($so, $socket); if ($res === false) { $msg = socket_strerror(socket_last_error()); $error = "Connect failed: {$msg}"; } else { $payload = json_encode(array('action' => 'refresh', 'user_id' => $discord_id)); $res = socket_write($so, $payload); if ($res === false) { $error = "Socket send failed"; } else { if ($res < strlen($payload)) { $error = "Socket did not send all data"; } } socket_shutdown($so); socket_close($so); } } }
/** * Creates a new socket * @return resource */ static function closeSocket($sock) { $ret_val = @socket_shutdown($sock, 2); // Socket close doesn't return anything, so we return the result of socket_shutdown (boolean) @socket_close($sock); return $ret_val; }
/** * Send request to the daemon * * @param string $execute * @return string Daemon answer * @todo Remove error operator */ function send_request($execute) { // @$socket = socket_create (AF_INET, SOCK_STREAM, 0); @($socket = socket_create(AF_UNIX, SOCK_STREAM, 0)); if ($socket < 0) { $errno = "socket_create() failed.\n"; return $errno; } // @$result = socket_connect ($socket, '127.0.0.1', 9876); @($result = socket_connect($socket, EasyConfig::$cfg->SOCK_EASYSCPD)); if ($result == false) { $errno = "socket_connect() failed.\n"; return $errno; } // read one line with welcome string socket_read($socket, 1024, PHP_NORMAL_READ); // $out = read_line($socket); // send reg check query // $query = $execute . "\r\n"; $query = trim($execute) . "\n"; socket_write($socket, $query, strlen($query)); // read answer from the daemon $out = socket_read($socket, 10240, PHP_NORMAL_READ); socket_shutdown($socket, 2); socket_close($socket); // sleep(1); // todo: prüfen ob das noch benötigt wird. Wenn keine Fehler mehr auftreten kann es entfernt werden // usleep(250); return trim($out); }
/** * Method send * * @param string $raw_text * * @return string $return_text */ public function send($raw_text) { if (!empty($raw_text)) { $this->raw_text = $raw_text; $xw = new xmlWriter(); $xw->openMemory(); $xw->startDocument('1.0'); $xw->startElement('wordsegmentation'); $xw->writeAttribute('version', '0.1'); $xw->startElement('option'); $xw->writeAttribute('showcategory', '1'); $xw->endElement(); $xw->startElement('authentication'); $xw->writeAttribute('username', $this->username); $xw->writeAttribute('password', $this->password); $xw->endElement(); $xw->startElement('text'); $xw->writeRaw($this->raw_text); $xw->endElement(); $xw->endElement(); $message = iconv("utf-8", "big5", $xw->outputMemory(true)); //send message to CKIP server set_time_limit(60); $protocol = getprotobyname("tcp"); $socket = socket_create(AF_INET, SOCK_STREAM, $protocol); socket_connect($socket, $this->server_ip, $this->server_port); socket_write($socket, $message); $this->return_text = iconv("big5", "utf-8", socket_read($socket, strlen($message) * 3)); socket_shutdown($socket); socket_close($socket); } return $this->return_text; }
/** * * @unlock * * @description * - unlock the port * * @parameters * - * * @return * - * */ public function unlock() { //free @socket_shutdown($this->_Sock, 2); @socket_close($this->_Sock); debug("unlock() :: Try to reset the port! [{$this->_Port}] "); }
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; }
public function close() { if ($this->connected) { socket_shutdown($this->socket); socket_close($this->socket); $this->socket = null; } }
private function refreshDiscordId($discordId) { $options = XenForo_Application::get('options'); if ($options->botSocket === '') { return; } XenForo_Error::debug("Refreshing user {$discordId}"); $so = socket_create(AF_UNIX, SOCK_DGRAM, 0); if ($so === false) { $msg = socket_strerror(socket_last_error()); $error = "Bot socket create failed: {$msg}"; throw new Exception($error); } $res = socket_connect($so, $options->botSocket); if ($res === false) { $msg = socket_strerror(socket_last_error()); $error = "Bot socket connect failed: {$msg}"; throw new Exception($error); } $payload = json_encode(array('action' => 'refresh', 'user_id' => $discordId)); $res = socket_write($so, $payload); socket_shutdown($so); socket_close($so); if ($res === false) { $error = "Bot socket send failed"; throw new Exception($error); } else { if ($res < strlen($payload)) { // This will probably never happen. $error = "Bot socket did not send all data"; throw new Exception($error); } } }
/** * @return bool */ public function disconnect() { if ($this->connection === null) { return true; } return socket_shutdown($this->connection); }
public static function CloseClient($Client) { if ($Client != Null) { @socket_shutdown($Client, 2); //Schließe den Socket in beiden Richtungen socket_close($Client); } }
public function disconnect() { if (!$this->usingProxy) { socket_shutdown($this->resSocket); } else { unset($this->proxyObject); } }
public function close() { if (is_resource($this->socket)) { @socket_shutdown($this->socket, 2); @socket_close($this->socket); } $this->disconnected = true; }
public function disconnect() { if (@socket_shutdown($this->sock, 2) == FALSE) { return aff_error(socket_strerror(socket_last_error())); } socket_close($this->sock); aff_ok("Closing connection client " . $this->id . " on server : " . $this->host . ":" . $this->port . " succeed."); }
public function close() { if (is_resource($this->socket)) { @socket_shutdown($this->socket, 2); @socket_close($this->socket); } $this->socket = (int) $this->socket; }
/** * Closes a socket if it was open */ public function __destruct() { // close the socket if opened if (is_resource($this->socket)) { @socket_shutdown($this->socket); @socket_close($this->socket); } }
function __destruct() { parent::__destruct(); if ($this->connected) { socket_shutdown($this->socket); $this->socket = null; $this->connected = false; } }
/** * 关闭链接 * */ public function close() { if ($this->isConnected) { socket_shutdown($this->sock, 2); socket_close($this->sock); $this->isConnected = false; //Log::addLog('close', $this->sock." socket_close() ok."); } }
public function disconnect() { if ($this->socket == null) { return; } socket_shutdown($this->socket); socket_close($this->socket); $this->socket = null; }
public function disconnect() { if ($this->validateConnection()) { socket_shutdown($this->_socket); socket_close($this->_socket); $this->_connectState = false; return true; } return false; }
private function disconnectSocket($socket_to_remove) { foreach ($this->sockets as $id => $socket) { if ($socket == $socket_to_remove) { unset($this->sockets[$id]); @socket_shutdown($socket, 2); @socket_close($socket); } } }
public function killSocket() { if (!is_resource($this->socket)) { // Already closed return; } @socket_shutdown($this->socket); // fugly: if the client dies while waiting for a connection, we just go through the usual hoops $this->close(); }
public function disconnect() { if ($this->isServer) { socket_shutdown($this->sessionSocketPointer); socket_close($this->sessionSocketPointer); } else { socket_shutdown($this->socketPointer); socket_close($this->socketPointer); } }
/** * 向GC发送数据 */ function sendToGC($words) { global $GCIp, $GCPort; $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); $con = socket_connect($socket, $GCIp, $GCPort); if (!$con) { socket_close($socket); return; } socket_write($socket, $words . "\n"); socket_shutdown($socket); socket_close($socket); }
public function testOnClose() { $this->app->expects($this->once())->method('onClose')->with($this->isInstanceOf('\\Ratchet\\ConnectionInterface')); $client = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); socket_set_option($client, SOL_SOCKET, SO_REUSEADDR, 1); socket_set_option($client, SOL_SOCKET, SO_SNDBUF, 4096); socket_set_block($client); socket_connect($client, 'localhost', $this->port); $this->server->loop->tick(); socket_shutdown($client, 1); socket_shutdown($client, 0); socket_close($client); $this->server->loop->tick(); }
private function send($packet) { if (!$this->socket) { $this->socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); } socket_connect($this->socket, gethostbyname($this->host), 80) or die("[-] Couldn't connect with specified host\r\n"); socket_write($this->socket, $packet, strlen($packet)) or die("[-] Couldn't send requrested packet\r\n"); while ($resp = socket_read($this->socket, 2048)) { $output .= $resp; } socket_shutdown($this->socket, 2); socket_close($this->socket); unset($this->socket); return $output; }
public function testOnClose() { $client = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); socket_set_option($client, SOL_SOCKET, SO_REUSEADDR, 1); socket_set_option($client, SOL_SOCKET, SO_SNDBUF, 4096); socket_set_block($client); socket_connect($client, 'localhost', $this->port); $this->server->loop->tick(); socket_shutdown($client, 1); socket_shutdown($client, 0); socket_close($client); $this->server->loop->tick(); usleep(5000); $this->assertSame($this->app->last['onOpen'][0], $this->app->last['onClose'][0]); }
function repl_loop($msgsock, $repl_vars) { $__scope_id = Lexical::init_closure("_reph", 224); Lexical::bind_lexing("_reph", 224, '$msgsock', $msgsock); $prompt = new \PharenLambda("reph\\_reph__lambdafunc18", Lexical::get_closure_id("_reph", $__scope_id)); Lexical::bind_lexing("_reph", 224, '$prompt', $prompt); $reph_prn = new \PharenLambda("reph\\_reph__lambdafunc19", Lexical::get_closure_id("_reph", $__scope_id)); Lexical::bind_lexing("_reph", 224, '$reph_prn', $reph_prn); if (false__question(repl\work("", $repl_vars, $prompt, $reph_prn))) { socket_shutdown($msgsock); return TRUE; } else { return NULL; } }
/** * Sends a payload string of Javascript code to the Zombie Node.js server. * * @param string $js String of Javascript code * * @return string */ public function socketSend($js) { $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); if (false === @socket_connect($socket, $this->host, $this->port)) { $errno = socket_last_error(); throw new \RuntimeException(sprintf("Could not establish connection: %s (%s)", socket_strerror($errno), $errno)); } socket_write($socket, $js, strlen($js)); socket_shutdown($socket, 1); $out = ''; while ($o = socket_read($socket, 2048)) { $out .= $o; } socket_close($socket); return $out; }
public function dispose() { if (is_null($this->_socket) || $this->_socket === false) { return true; } $e =& new Event('beforeClose', $this, 'Le serveur va être arrêté...'); $this->dispatch($e); foreach ($this->_clients as $uid => $client) { $this->removeClient($this->_clients[$uid]); } @socket_shutdown($this->_socket, 2); socket_close($this->_socket); $this->_socket = null; $e =& new Event('close', $this, 'Le serveur est arrêté.'); $this->dispatch($e); $this->removeAllEventListeners(); }