paho/doc/API/async.html

33 lines
3.7 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>MQTT Client: Asynchronous vs synchronous client applications</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Generated by Doxygen 1.6.3 -->
<div class="navigation" id="top">
<div class="tabs">
<ul>
<li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
<li class="current"><a href="pages.html"><span>Related&nbsp;Pages</span></a></li>
<li><a href="annotated.html"><span>Data&nbsp;Structures</span></a></li>
<li><a href="files.html"><span>Files</span></a></li>
</ul>
</div>
</div>
<div class="contents">
<h1><a class="anchor" id="async">Asynchronous vs synchronous client applications </a></h1><p>The client library supports two modes of operation. These are referred to as <b>synchronous</b> and <b>asynchronous</b> modes. If your application calls <a class="el" href="_m_q_t_t_client_8h.html#aad27d07782991a4937ebf2f39a021f83">MQTTClient_setCallbacks()</a>, this puts the client into asynchronous mode, otherwise it operates in synchronous mode.</p>
<p>In synchronous mode, the client application runs on a single thread. Messages are published using the <a class="el" href="_m_q_t_t_client_8h.html#aa061f83fbed3a23177cca8714780ffbd">MQTTClient_publish()</a> and <a class="el" href="_m_q_t_t_client_8h.html#a288d6c8d4919f06e991be2435f649676">MQTTClient_publishMessage()</a> functions. To determine that a QoS1 or QoS2 (see <a class="el" href="qos.html">Quality of service</a>) message has been successfully delivered, the application must call the <a class="el" href="_m_q_t_t_client_8h.html#a83807ec81fe8c3941e368ab329d43067">MQTTClient_waitForCompletion()</a> function. An example showing synchronous publication is shown in <a class="el" href="pubsync.html">Synchronous publication example</a>. Receiving messages in synchronous mode uses the <a class="el" href="_m_q_t_t_client_8h.html#a4c2df88d00a3dadd510a8cb774739366">MQTTClient_receive()</a> function. Client applicaitons must call either <a class="el" href="_m_q_t_t_client_8h.html#a4c2df88d00a3dadd510a8cb774739366">MQTTClient_receive()</a> or <a class="el" href="_m_q_t_t_client_8h.html#a8ad3d29864a9ca08202b0832e0f6678e">MQTTClient_yield()</a> relatively frequently in order to allow processing of acknowledgements and the MQTT "pings" that keep the network connection to the server alive.</p>
<p>In asynchronous mode, the client application runs on several threads. The main program calls functions in the client library to publish and subscribe, just as for the synchronous mode. Processing of handshaking and maintaining the network connection is performed in the background, however. Notifications of status and message reception are provided to the client application using callbacks registered with the library by the call to <a class="el" href="_m_q_t_t_client_8h.html#aad27d07782991a4937ebf2f39a021f83">MQTTClient_setCallbacks()</a> (see <a class="el" href="_m_q_t_t_client_8h.html#aa42130dd069e7e949bcab37b6dce64a5">MQTTClient_messageArrived()</a>, <a class="el" href="_m_q_t_t_client_8h.html#a6bb253f16754e7cc81798c9fda0e36cf">MQTTClient_connectionLost()</a> and <a class="el" href="_m_q_t_t_client_8h.html#abef83794d8252551ed248cde6eb845a6">MQTTClient_deliveryComplete()</a>). </p>
</div>
<hr class="footer"/><address style="text-align: right;"><small>Generated on Tue Jul 3 15:17:14 2012 for MQTT Client by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.3 </small></address>
</body>
</html>