<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Connect to the remote TCP or UDP port.</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="swoole-client.close.html">Swoole\Client::close</a></div> <div class="next" style="text-align: right; float: right;"><a href="swoole-client.construct.html">Swoole\Client::__construct</a></div> <div class="up"><a href="class.swoole-client.html">Swoole\Client</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="swoole-client.connect" class="refentry"> <div class="refnamediv"> <h1 class="refname">Swoole\Client::connect</h1> <p class="verinfo">(PHP 5 >= 5.2.0, PHP 7, PECL swoole >= 1.9.0)</p><p class="refpurpose"><span class="refname">Swoole\Client::connect</span> — <span class="dc-title">Connect to the remote TCP or UDP port.</span></p> </div> <div class="refsect1 description" id="refsect1-swoole-client.connect-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="type">bool</span> <span class="methodname"><strong>Swoole\Client::connect</strong></span> ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$host</code></span> [, <span class="methodparam"><span class="type">integer</span> <code class="parameter">$port</code></span> [, <span class="methodparam"><span class="type">integer</span> <code class="parameter">$timeout</code></span> [, <span class="methodparam"><span class="type">integer</span> <code class="parameter">$flag</code></span> ]]] )</div> <p class="para rdfs-comment"> </p> </div> <div class="refsect1 parameters" id="refsect1-swoole-client.connect-parameters"> <h3 class="title">Parameters</h3> <dl> <dt> <code class="parameter">host</code></dt> <dd> <p class="para"> The host name of the remote address. </p> </dd> <dt> <code class="parameter">port</code></dt> <dd> <p class="para"> The port number of the remote address. </p> </dd> <dt> <code class="parameter">timeout</code></dt> <dd> <p class="para"> The timeout(second) of connect/send/recv, the dafault value is 0.1s </p> </dd> <dt> <code class="parameter">flag</code></dt> <dd> <p class="para"> If the type of client is UDP, the $flag means if to enable the configuration udp_connect. If the configuration udp_connect is enabled, the client will only receive the data from specified ip:port. If the type of client is TCP and the $flag is set to 1, it must use swoole_client_select to check the connection status before send/recv. </p> </dd> </dl> </div> <div class="refsect1 returnvalues" id="refsect1-swoole-client.connect-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Whether the connection is established. </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="swoole-client.close.html">Swoole\Client::close</a></div> <div class="next" style="text-align: right; float: right;"><a href="swoole-client.construct.html">Swoole\Client::__construct</a></div> <div class="up"><a href="class.swoole-client.html">Swoole\Client</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>