accept udp packet
@param resource $socket
505257
public function acceptUdp($socket){
        $peer = null;
        $message = stream_socket_recvfrom($socket , $this->max_udp_packet_size, 0, $peer);
        
        //thundering herd EAGAIN (Resource temporarily unavailable)
        if(!$peer || $message === false || $message === ''){
            return false;
        }
        
        $local = stream_socket_get_name($socket, false);
        
        $event = new UdpMessageEvent(['message'=>$message, 'socket'=>$socket]);
        
        if($this->parser) {
            $message = call_user_func([$this->parser, 'decode'], $message, null);
        }
        
        $event->local = $local;
        $event->peer = $peer;
        
        $this->trigger(Server::ON_UDP_PACKET, $event);
    }
1202404
protected function getStream($socket)
    {
        if (class_exists(DuplexResourceStream::class)) {
            return new DuplexResourceStream($socket, $this->getLoop());
        }

        return new Stream($socket, $this->getLoop());
    }
23827
private function handleClient(Socket $socket): Generator
    {
        yield from log()->log(
            Log::INFO,
            'Accepted client from %s:%d on %s:%d',
            $socket->getRemoteAddress(),
            $socket->getRemotePort(),
            $socket->getLocalAddress(),
            $socket->getLocalPort()
        );

        // Create a new context object for this client.
        $context = new ClientContext($socket, $this->encoder, $this->accessLayer);

        try {
            // Send a welcome message.
            $welcome = new Response(200, 'Ready');
            yield from $context->writeResponse($welcome);

            // Command loop
            while ($socket->isOpen()) {
                // Parse incoming commands.
                $command = yield from $context->readCommand();

                // Determine the command name and choose how to handle it.
                $handler = null;
                switch ($command->name()) {
                    // Mandatory commands
                    case 'CAPABILITIES':
                        $handler = $this->getHandler(handlers\CapabilitiesHandler::class);
                        break;
                    case 'HEAD':
                        $handler = $this->getHandler(handlers\HeadHandler::class);
                        break;
                    case 'HELP':
                        $handler = $this->getHandler(handlers\HelpHandler::class);
                        break;
                    // We don't advertise MODE support, but some readers need it
                    case 'MODE':
                        $handler = $this->getHandler(handlers\ModeHandler::class);
                        break;
                    case 'STAT':
                        $handler = $this->getHandler(handlers\StatHandler::class);
                        break;
                    case 'QUIT':
                        yield from $context->writeResponse(new Response(205, 'Closing connection'));
                        break 2; // stop command loop

                    // LIST commands
                    case 'LIST':
                        $handler = $this->getHandler(handlers\ListHandler::class);
                        break;

                    // NEWNEWS commands
                    case 'NEWNEWS':
                        $handler = $this->getHandler(handlers\NewNewsHandler::class);
                        break;

                    // POST commands
                    case 'POST':
                        $handler = $this->getHandler(handlers\PostHandler::class);
                        break;

                    // READER commands
                    case 'ARTICLE':
                        $handler = $this->getHandler(handlers\ArticleHandler::class);
                        break;
                    case 'BODY':
                        $handler = $this->getHandler(handlers\BodyHandler::class);
                        break;
                    case 'DATE':
                        $handler = $this->getHandler(handlers\DateHandler::class);
                        break;
                    case 'GROUP':
                        $handler = $this->getHandler(handlers\GroupHandler::class);
                        break;
                    case 'LAST':
                        $handler = $this->getHandler(handlers\LastHandler::class);
                        break;
                    case 'LISTGROUP':
                        $handler = $this->getHandler(handlers\ListGroupHandler::class);
                        break;
                    case 'NEWGROUPS':
                        $handler = $this->getHandler(handlers\NewGroupsHandler::class);
                        break;
                    case 'NEXT':
                        $handler = $this->getHandler(handlers\NextHandler::class);
                        break;
                }

                // Unknown command
                if (!$handler) {
                    yield from $context->writeResponse(new Response(500, 'Unknown command'));
                } else {
                    // Execute the selected command handler.
                    try {
                        yield from $handler->handle($command, $context);
                    } catch (\Throwable $e) {
                        yield from log()->log(Log::ERROR, 'Error handling command: ' . $e);
                        yield from $context->writeResponse(new Response(502, 'Server error'));
                    }
                }
            }
        } catch (UnreadableException $e) {
            // Client disconnected.
        } catch (UnwritableException $e) {
            // Client disconnected.
        } catch (ClosedException $e) {
            // Client disconnected.
        }

        yield from log()->log(
            Log::INFO,
            'Disconnected client from %s:%d on %s:%d',
            $socket->getRemoteAddress(),
            $socket->getRemotePort(),
            $socket->getLocalAddress(),
            $socket->getLocalPort()
        );

        // Close the connection to the client.
        if ($socket->isOpen()) {
            $socket->close();
        }
    }
1240453
public static function accept($request, $handler)
    {
        static::checkRequest($request);

        $webSocketAccept = base64_encode(
            sha1($request->getWebSocketKey().'258EAFA5-E914-47DA-95CA-C5AB0DC85B11', true)
        );

        $response = static::create('', self::HTTP_SWITCHING_PROTOCOLS);

        $response->header('Upgrade', 'websocket');
        $response->header('Connection', 'Upgrade');
        $response->header('Sec-WebSocket-Accept', $webSocketAccept);
        $response->header('Sec-WebSocket-Version', '13');

        // WebSocket connection to 'ws://127.0.0.1:9502/'
        // failed: Error during WebSocket handshake:
        // Response must not include 'Sec-WebSocket-Protocol' header if not present in request: websocket
        if ($webSocketProtocol = $request->getWebSocketProtocol()) {
            $response->header('Sec-WebSocket-Protocol', $webSocketProtocol);
        }

        if ($handler !== null) {
            $response->setHandler($handler);
        }

        return $response;
    }
440410
public function setUnixSocket( ?string $socket ) : MySQL
   {

      if ( ! $this->_supportedAttributes->get( 'unix_socket' )->validateValue( $socket ) )
      {
         throw new ArgumentException( 'socket', $socket, 'Invalid unix socket!' );
      }

      $this->_attributes[ 'unix_socket' ] = $socket;

      return $this;

   }
1257809
private function accept(SocketServer $server, int $cryptoMethod, float $timeout, bool $allowPersistent): \Generator
    {
        yield from $this->log->log(
            Log::INFO,
            'HTTP server listening on %s:%d',
            $server->getAddress(),
            $server->getPort()
        );

        while ($server->isOpen()) {
            try {
                $coroutine = new Coroutine(
                    $this->process(yield from $server->accept(), $cryptoMethod, $timeout, $allowPersistent)
                );
                $coroutine->done(null, $this->onError);
            } catch (Throwable $exception) {
                if ($this->isOpen()) {
                    throw $exception;
                }
            }
        }
    }
942399
public function write($buffer)
    {
        $ret = @socket_write($this->resource, $buffer);
        if ($ret === false) {
            throw Exception::createFromSocketResource($this->resource);
        }
        return $ret;
    }
1073395
public function checkConnection($socket)
    {
        // Remove EV_EXPECT for windows.
        if(DIRECTORY_SEPARATOR === '\\') {
            Worker::$globalEvent->del($socket, EventInterface::EV_EXCEPT);
        }
        // Check socket state.
        if ($address = stream_socket_get_name($socket, true)) {
            // Remove write listener.
            Worker::$globalEvent->del($socket, EventInterface::EV_WRITE);
            // Nonblocking.
            stream_set_blocking($socket, 0);
            // Compatible with hhvm
            if (function_exists('stream_set_read_buffer')) {
                stream_set_read_buffer($socket, 0);
            }
            // Try to open keepalive for tcp and disable Nagle algorithm.
            if (function_exists('socket_import_stream') && $this->transport === 'tcp') {
                $raw_socket = socket_import_stream($socket);
                socket_set_option($raw_socket, SOL_SOCKET, SO_KEEPALIVE, 1);
                socket_set_option($raw_socket, SOL_TCP, TCP_NODELAY, 1);
            }
            // Register a listener waiting read event.
            Worker::$globalEvent->add($socket, EventInterface::EV_READ, array($this, 'baseRead'));
            // There are some data waiting to send.
            if ($this->_sendBuffer) {
                Worker::$globalEvent->add($socket, EventInterface::EV_WRITE, array($this, 'baseWrite'));
            }
            $this->_status                = self::STATUS_ESTABLISHED;
            $this->_remoteAddress         = $address;
            $this->_sslHandshakeCompleted = true;

            // Try to emit onConnect callback.
            if ($this->onConnect) {
                try {
                    call_user_func($this->onConnect, $this);
                } catch (\Exception $e) {
                    Worker::log($e);
                    exit(250);
                } catch (\Error $e) {
                    Worker::log($e);
                    exit(250);
                }
            }
            // Try to emit protocol::onConnect
            if (method_exists($this->protocol, 'onConnect')) {
                try {
                    call_user_func(array($this->protocol, 'onConnect'), $this);
                } catch (\Exception $e) {
                    Worker::log($e);
                    exit(250);
                } catch (\Error $e) {
                    Worker::log($e);
                    exit(250);
                }
            }
        } else {
            // Connection failed.
            $this->emitError(WORKERMAN_CONNECT_FAIL, 'connect ' . $this->_remoteAddress . ' fail after ' . round(microtime(true) - $this->_connectStartTime, 4) . ' seconds');
            if ($this->_status === self::STATUS_CLOSING) {
                $this->destroy();
            }
            if ($this->_status === self::STATUS_CLOSED) {
                $this->onConnect = null;
            }
        }
    }
1325656
public function onSocketConnect($socket, Connection $connection): void
    {
        $this->checkConnections($connection);
        $this->checkConnectionsPerIp($connection);
    }
1103669
protected function sendData($host, $port, $message)
    {
        $socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);

        return socket_sendto($socket, $message, strlen($message), 0, $host, $port);
    }
261710
def accept
      while true
	s = @socket.accept
	break if (@acl ? @acl.allow_socket?(s) : true) 
	s.close
      end
      if @config[:tcp_original_host].to_s.size == 0
        uri = "druby://#{s.addr[3]}:#{@config[:tcp_port]}"
      else
        uri = @uri
      end
      self.class.new(uri, s, @config)
    end
183529
public function send(Socket $socket, Request $request, array $options = []): \Generator
    {
        $timeout = isset($options['timeout']) ? (float) $options['timeout'] : self::DEFAULT_TIMEOUT;
        $allowPersistent = isset($options['allow_persistent']) ? (bool) $options['allow_persistent'] : true;

        $request = yield from $this->driver->buildRequest($request, $timeout, $allowPersistent);

        yield from $this->driver->writeRequest($socket, $request, $timeout);

        return yield from $this->driver->readResponse($socket, $timeout);
    }
204167
function send($data)
    {
        $len = strlen($data);
        $n = socket_sendto($this->sock, $data, $len, 0, $this->host, $this->port);

        if ($n === false or $n < $len) {
            $this->set_error();
            return false;
        } else {
            return $n;
        }
    }
432048
protected function writeToSocket($socket, $message)
    {
        socket_sendto($socket, $message, strlen($message), 0, PAPERTRAIL_HOST, PAPERTRAIL_PORT);
    }
496872
protected function write($socket, $value)
    {
        $value = $this->serialize($value) . PHP_EOL;
        $written = 0;
        while ($written < strlen($value)) {
            $bytes = fwrite($socket, substr($value, $written));
            if ($bytes === false) {
                return false;
            }
            $written += $bytes;
        }
        return true;
    }
103548
function _send_sftp_packet($type, $data)
    {
        $packet = $this->request_id !== false ?
            pack('NCNa*', strlen($data) + 5, $type, $this->request_id, $data) :
            pack('NCa*',  strlen($data) + 1, $type, $data);

        $start = strtok(microtime(), ' ') + strtok(''); // http://php.net/microtime#61838
        $result = $this->_send_channel_packet(self::CHANNEL, $packet);
        $stop = strtok(microtime(), ' ') + strtok('');

        if (defined('NET_SFTP_LOGGING')) {
            $packet_type = '-> ' . $this->packet_types[$type] .
                           ' (' . round($stop - $start, 4) . 's)';
            if (NET_SFTP_LOGGING == self::LOG_REALTIME) {
                echo "<pre>\r\n" . $this->_format_log(array($data), array($packet_type)) . "\r\n</pre>\r\n";
                flush();
                ob_flush();
            } else {
                $this->packet_type_log[] = $packet_type;
                if (NET_SFTP_LOGGING == self::LOG_COMPLEX) {
                    $this->packet_log[] = $data;
                }
            }
        }

        return $result;
    }
499221
function send_request($packet)
    {
        curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($this->curl, CURLOPT_POSTFIELDS, $packet);
        $retval = curl_exec($this->curl);

        return $retval;
    }