\!/ KyuuKazami \!/

Path : /usr/share/doc/python34-docs-3.4.3/library/
Upload :
Current File : //usr/share/doc/python34-docs-3.4.3/library/asyncio-protocol.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/html; charset=utf-8" />
    
    <title>18.5.4. Transports and protocols (low-level API) &mdash; Python 3.4.3 documentation</title>
    
    <link rel="stylesheet" href="../_static/pydoctheme.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../',
        VERSION:     '3.4.3',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <script type="text/javascript" src="../_static/sidebar.js"></script>
    <link rel="search" type="application/opensearchdescription+xml"
          title="Search within Python 3.4.3 documentation"
          href="../_static/opensearch.xml"/>
    <link rel="author" title="About these documents" href="../about.html" />
    <link rel="copyright" title="Copyright" href="../copyright.html" />
    <link rel="top" title="Python 3.4.3 documentation" href="../index.html" />
    <link rel="up" title="18.5. asyncio – Asynchronous I/O, event loop, coroutines and tasks" href="asyncio.html" />
    <link rel="next" title="18.5.5. Streams (high-level API)" href="asyncio-stream.html" />
    <link rel="prev" title="18.5.3. Tasks and coroutines" href="asyncio-task.html" />
    <link rel="shortcut icon" type="image/png" href="../_static/py.png" />
    <script type="text/javascript" src="../_static/copybutton.js"></script>
    
    
 

  </head>
  <body>  
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="asyncio-stream.html" title="18.5.5. Streams (high-level API)"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="asyncio-task.html" title="18.5.3. Tasks and coroutines"
             accesskey="P">previous</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="https://www.python.org/">Python</a> &raquo;</li>
        <li>
          <a href="../index.html">3.4.3 Documentation</a> &raquo;
        </li>

          <li><a href="index.html" >The Python Standard Library</a> &raquo;</li>
          <li><a href="ipc.html" >18. Interprocess Communication and Networking</a> &raquo;</li>
          <li><a href="asyncio.html" accesskey="U">18.5. <tt class="docutils literal"><span class="pre">asyncio</span></tt> &#8211; Asynchronous I/O, event loop, coroutines and tasks</a> &raquo;</li> 
      </ul>
    </div>    

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="transports-and-protocols-low-level-api">
<h1>18.5.4. Transports  and protocols (low-level API)<a class="headerlink" href="#transports-and-protocols-low-level-api" title="Permalink to this headline">¶</a></h1>
<div class="section" id="transports">
<span id="asyncio-transport"></span><h2>18.5.4.1. Transports<a class="headerlink" href="#transports" title="Permalink to this headline">¶</a></h2>
<p>Transports are classes provided by <a class="reference internal" href="asyncio.html#module-asyncio" title="asyncio: Asynchronous I/O, event loop, coroutines and tasks."><tt class="xref py py-mod docutils literal"><span class="pre">asyncio</span></tt></a> in order to abstract
various kinds of communication channels.  You generally won&#8217;t instantiate
a transport yourself; instead, you will call a <a class="reference internal" href="asyncio-eventloop.html#asyncio.BaseEventLoop" title="asyncio.BaseEventLoop"><tt class="xref py py-class docutils literal"><span class="pre">BaseEventLoop</span></tt></a> method
which will create the transport and try to initiate the underlying
communication channel, calling you back when it succeeds.</p>
<p>Once the communication channel is established, a transport is always
paired with a <a class="reference internal" href="#asyncio-protocol"><em>protocol</em></a> instance.  The protocol can
then call the transport&#8217;s methods for various purposes.</p>
<p><a class="reference internal" href="asyncio.html#module-asyncio" title="asyncio: Asynchronous I/O, event loop, coroutines and tasks."><tt class="xref py py-mod docutils literal"><span class="pre">asyncio</span></tt></a> currently implements transports for TCP, UDP, SSL, and
subprocess pipes.  The methods available on a transport depend on
the transport&#8217;s kind.</p>
<div class="section" id="basetransport">
<h3>18.5.4.1.1. BaseTransport<a class="headerlink" href="#basetransport" title="Permalink to this headline">¶</a></h3>
<dl class="class">
<dt id="asyncio.BaseTransport">
<em class="property">class </em><tt class="descclassname">asyncio.</tt><tt class="descname">BaseTransport</tt><a class="headerlink" href="#asyncio.BaseTransport" title="Permalink to this definition">¶</a></dt>
<dd><p>Base class for transports.</p>
<dl class="method">
<dt id="asyncio.BaseTransport.close">
<tt class="descname">close</tt><big>(</big><em>self</em><big>)</big><a class="headerlink" href="#asyncio.BaseTransport.close" title="Permalink to this definition">¶</a></dt>
<dd><p>Close the transport.  If the transport has a buffer for outgoing
data, buffered data will be flushed asynchronously.  No more data
will be received.  After all buffered data is flushed, the
protocol&#8217;s <tt class="xref py py-meth docutils literal"><span class="pre">connection_lost()</span></tt> method will be called with
<a class="reference internal" href="constants.html#None" title="None"><tt class="xref py py-const docutils literal"><span class="pre">None</span></tt></a> as its argument.</p>
</dd></dl>

<dl class="method">
<dt id="asyncio.BaseTransport.get_extra_info">
<tt class="descname">get_extra_info</tt><big>(</big><em>name</em>, <em>default=None</em><big>)</big><a class="headerlink" href="#asyncio.BaseTransport.get_extra_info" title="Permalink to this definition">¶</a></dt>
<dd><p>Return optional transport information.  <em>name</em> is a string representing
the piece of transport-specific information to get, <em>default</em> is the
value to return if the information doesn&#8217;t exist.</p>
<p>This method allows transport implementations to easily expose
channel-specific information.</p>
<ul class="simple">
<li>socket:<ul>
<li><tt class="docutils literal"><span class="pre">'peername'</span></tt>: the remote address to which the socket is connected,
result of <a class="reference internal" href="socket.html#socket.socket.getpeername" title="socket.socket.getpeername"><tt class="xref py py-meth docutils literal"><span class="pre">socket.socket.getpeername()</span></tt></a> (<tt class="docutils literal"><span class="pre">None</span></tt> on error)</li>
<li><tt class="docutils literal"><span class="pre">'socket'</span></tt>: <a class="reference internal" href="socket.html#socket.socket" title="socket.socket"><tt class="xref py py-class docutils literal"><span class="pre">socket.socket</span></tt></a> instance</li>
<li><tt class="docutils literal"><span class="pre">'sockname'</span></tt>: the socket&#8217;s own address,
result of <a class="reference internal" href="socket.html#socket.socket.getsockname" title="socket.socket.getsockname"><tt class="xref py py-meth docutils literal"><span class="pre">socket.socket.getsockname()</span></tt></a></li>
</ul>
</li>
<li>SSL socket:<ul>
<li><tt class="docutils literal"><span class="pre">'compression'</span></tt>: the compression algorithm being used as a string,
or <tt class="docutils literal"><span class="pre">None</span></tt> if the connection isn&#8217;t compressed; result of
<a class="reference internal" href="ssl.html#ssl.SSLSocket.compression" title="ssl.SSLSocket.compression"><tt class="xref py py-meth docutils literal"><span class="pre">ssl.SSLSocket.compression()</span></tt></a></li>
<li><tt class="docutils literal"><span class="pre">'cipher'</span></tt>: a three-value tuple containing the name of the cipher
being used, the version of the SSL protocol that defines its use, and
the number of secret bits being used; result of
<a class="reference internal" href="ssl.html#ssl.SSLSocket.cipher" title="ssl.SSLSocket.cipher"><tt class="xref py py-meth docutils literal"><span class="pre">ssl.SSLSocket.cipher()</span></tt></a></li>
<li><tt class="docutils literal"><span class="pre">'peercert'</span></tt>: peer certificate; result of
<a class="reference internal" href="ssl.html#ssl.SSLSocket.getpeercert" title="ssl.SSLSocket.getpeercert"><tt class="xref py py-meth docutils literal"><span class="pre">ssl.SSLSocket.getpeercert()</span></tt></a></li>
<li><tt class="docutils literal"><span class="pre">'sslcontext'</span></tt>: <a class="reference internal" href="ssl.html#ssl.SSLContext" title="ssl.SSLContext"><tt class="xref py py-class docutils literal"><span class="pre">ssl.SSLContext</span></tt></a> instance</li>
</ul>
</li>
<li>pipe:<ul>
<li><tt class="docutils literal"><span class="pre">'pipe'</span></tt>: pipe object</li>
</ul>
</li>
<li>subprocess:<ul>
<li><tt class="docutils literal"><span class="pre">'subprocess'</span></tt>: <a class="reference internal" href="subprocess.html#subprocess.Popen" title="subprocess.Popen"><tt class="xref py py-class docutils literal"><span class="pre">subprocess.Popen</span></tt></a> instance</li>
</ul>
</li>
</ul>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="readtransport">
<h3>18.5.4.1.2. ReadTransport<a class="headerlink" href="#readtransport" title="Permalink to this headline">¶</a></h3>
<dl class="class">
<dt id="asyncio.ReadTransport">
<em class="property">class </em><tt class="descclassname">asyncio.</tt><tt class="descname">ReadTransport</tt><a class="headerlink" href="#asyncio.ReadTransport" title="Permalink to this definition">¶</a></dt>
<dd><p>Interface for read-only transports.</p>
<dl class="method">
<dt id="asyncio.ReadTransport.pause_reading">
<tt class="descname">pause_reading</tt><big>(</big><big>)</big><a class="headerlink" href="#asyncio.ReadTransport.pause_reading" title="Permalink to this definition">¶</a></dt>
<dd><p>Pause the receiving end of the transport.  No data will be passed to
the protocol&#8217;s <tt class="xref py py-meth docutils literal"><span class="pre">data_received()</span></tt> method until <a class="reference internal" href="#asyncio.ReadTransport.resume_reading" title="asyncio.ReadTransport.resume_reading"><tt class="xref py py-meth docutils literal"><span class="pre">resume_reading()</span></tt></a>
is called.</p>
</dd></dl>

<dl class="method">
<dt id="asyncio.ReadTransport.resume_reading">
<tt class="descname">resume_reading</tt><big>(</big><big>)</big><a class="headerlink" href="#asyncio.ReadTransport.resume_reading" title="Permalink to this definition">¶</a></dt>
<dd><p>Resume the receiving end.  The protocol&#8217;s <tt class="xref py py-meth docutils literal"><span class="pre">data_received()</span></tt> method
will be called once again if some data is available for reading.</p>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="writetransport">
<h3>18.5.4.1.3. WriteTransport<a class="headerlink" href="#writetransport" title="Permalink to this headline">¶</a></h3>
<dl class="class">
<dt id="asyncio.WriteTransport">
<em class="property">class </em><tt class="descclassname">asyncio.</tt><tt class="descname">WriteTransport</tt><a class="headerlink" href="#asyncio.WriteTransport" title="Permalink to this definition">¶</a></dt>
<dd><p>Interface for write-only transports.</p>
<dl class="method">
<dt id="asyncio.WriteTransport.abort">
<tt class="descname">abort</tt><big>(</big><big>)</big><a class="headerlink" href="#asyncio.WriteTransport.abort" title="Permalink to this definition">¶</a></dt>
<dd><p>Close the transport immediately, without waiting for pending operations
to complete.  Buffered data will be lost.  No more data will be received.
The protocol&#8217;s <tt class="xref py py-meth docutils literal"><span class="pre">connection_lost()</span></tt> method will eventually be
called with <a class="reference internal" href="constants.html#None" title="None"><tt class="xref py py-const docutils literal"><span class="pre">None</span></tt></a> as its argument.</p>
</dd></dl>

<dl class="method">
<dt id="asyncio.WriteTransport.can_write_eof">
<tt class="descname">can_write_eof</tt><big>(</big><big>)</big><a class="headerlink" href="#asyncio.WriteTransport.can_write_eof" title="Permalink to this definition">¶</a></dt>
<dd><p>Return <a class="reference internal" href="constants.html#True" title="True"><tt class="xref py py-const docutils literal"><span class="pre">True</span></tt></a> if the transport supports <a class="reference internal" href="#asyncio.WriteTransport.write_eof" title="asyncio.WriteTransport.write_eof"><tt class="xref py py-meth docutils literal"><span class="pre">write_eof()</span></tt></a>,
<a class="reference internal" href="constants.html#False" title="False"><tt class="xref py py-const docutils literal"><span class="pre">False</span></tt></a> if not.</p>
</dd></dl>

<dl class="method">
<dt id="asyncio.WriteTransport.get_write_buffer_size">
<tt class="descname">get_write_buffer_size</tt><big>(</big><big>)</big><a class="headerlink" href="#asyncio.WriteTransport.get_write_buffer_size" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the current size of the output buffer used by the transport.</p>
</dd></dl>

<dl class="method">
<dt id="asyncio.WriteTransport.get_write_buffer_limits">
<tt class="descname">get_write_buffer_limits</tt><big>(</big><big>)</big><a class="headerlink" href="#asyncio.WriteTransport.get_write_buffer_limits" title="Permalink to this definition">¶</a></dt>
<dd><p>Get the <em>high</em>- and <em>low</em>-water limits for write flow control. Return a
tuple <tt class="docutils literal"><span class="pre">(low,</span> <span class="pre">high)</span></tt> where <em>low</em> and <em>high</em> are positive number of
bytes.</p>
<p>Use <a class="reference internal" href="#asyncio.WriteTransport.set_write_buffer_limits" title="asyncio.WriteTransport.set_write_buffer_limits"><tt class="xref py py-meth docutils literal"><span class="pre">set_write_buffer_limits()</span></tt></a> to set the limits.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.4.2.</span></p>
</div>
</dd></dl>

<dl class="method">
<dt id="asyncio.WriteTransport.set_write_buffer_limits">
<tt class="descname">set_write_buffer_limits</tt><big>(</big><em>high=None</em>, <em>low=None</em><big>)</big><a class="headerlink" href="#asyncio.WriteTransport.set_write_buffer_limits" title="Permalink to this definition">¶</a></dt>
<dd><p>Set the <em>high</em>- and <em>low</em>-water limits for write flow control.</p>
<p>These two values control when call the protocol&#8217;s
<tt class="xref py py-meth docutils literal"><span class="pre">pause_writing()</span></tt> and <tt class="xref py py-meth docutils literal"><span class="pre">resume_writing()</span></tt> methods are called.
If specified, the low-water limit must be less than or equal to the
high-water limit.  Neither <em>high</em> nor <em>low</em> can be negative.</p>
<p>The defaults are implementation-specific.  If only the
high-water limit is given, the low-water limit defaults to a
implementation-specific value less than or equal to the
high-water limit.  Setting <em>high</em> to zero forces <em>low</em> to zero as
well, and causes <tt class="xref py py-meth docutils literal"><span class="pre">pause_writing()</span></tt> to be called whenever the
buffer becomes non-empty.  Setting <em>low</em> to zero causes
<tt class="xref py py-meth docutils literal"><span class="pre">resume_writing()</span></tt> to be called only once the buffer is empty.
Use of zero for either limit is generally sub-optimal as it
reduces opportunities for doing I/O and computation
concurrently.</p>
<p>Use <a class="reference internal" href="#asyncio.WriteTransport.get_write_buffer_limits" title="asyncio.WriteTransport.get_write_buffer_limits"><tt class="xref py py-meth docutils literal"><span class="pre">get_write_buffer_limits()</span></tt></a> to get the limits.</p>
</dd></dl>

<dl class="method">
<dt id="asyncio.WriteTransport.write">
<tt class="descname">write</tt><big>(</big><em>data</em><big>)</big><a class="headerlink" href="#asyncio.WriteTransport.write" title="Permalink to this definition">¶</a></dt>
<dd><p>Write some <em>data</em> bytes to the transport.</p>
<p>This method does not block; it buffers the data and arranges for it
to be sent out asynchronously.</p>
</dd></dl>

<dl class="method">
<dt id="asyncio.WriteTransport.writelines">
<tt class="descname">writelines</tt><big>(</big><em>list_of_data</em><big>)</big><a class="headerlink" href="#asyncio.WriteTransport.writelines" title="Permalink to this definition">¶</a></dt>
<dd><p>Write a list (or any iterable) of data bytes to the transport.
This is functionally equivalent to calling <a class="reference internal" href="#asyncio.WriteTransport.write" title="asyncio.WriteTransport.write"><tt class="xref py py-meth docutils literal"><span class="pre">write()</span></tt></a> on each
element yielded by the iterable, but may be implemented more efficiently.</p>
</dd></dl>

<dl class="method">
<dt id="asyncio.WriteTransport.write_eof">
<tt class="descname">write_eof</tt><big>(</big><big>)</big><a class="headerlink" href="#asyncio.WriteTransport.write_eof" title="Permalink to this definition">¶</a></dt>
<dd><p>Close the write end of the transport after flushing buffered data.
Data may still be received.</p>
<p>This method can raise <a class="reference internal" href="exceptions.html#NotImplementedError" title="NotImplementedError"><tt class="xref py py-exc docutils literal"><span class="pre">NotImplementedError</span></tt></a> if the transport
(e.g. SSL) doesn&#8217;t support half-closes.</p>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="datagramtransport">
<h3>18.5.4.1.4. DatagramTransport<a class="headerlink" href="#datagramtransport" title="Permalink to this headline">¶</a></h3>
<dl class="method">
<dt id="asyncio.DatagramTransport.sendto">
<tt class="descclassname">DatagramTransport.</tt><tt class="descname">sendto</tt><big>(</big><em>data</em>, <em>addr=None</em><big>)</big><a class="headerlink" href="#asyncio.DatagramTransport.sendto" title="Permalink to this definition">¶</a></dt>
<dd><p>Send the <em>data</em> bytes to the remote peer given by <em>addr</em> (a
transport-dependent target address).  If <em>addr</em> is <a class="reference internal" href="constants.html#None" title="None"><tt class="xref py py-const docutils literal"><span class="pre">None</span></tt></a>, the
data is sent to the target address given on transport creation.</p>
<p>This method does not block; it buffers the data and arranges for it
to be sent out asynchronously.</p>
</dd></dl>

<dl class="method">
<dt id="asyncio.DatagramTransport.abort">
<tt class="descclassname">DatagramTransport.</tt><tt class="descname">abort</tt><big>(</big><big>)</big><a class="headerlink" href="#asyncio.DatagramTransport.abort" title="Permalink to this definition">¶</a></dt>
<dd><p>Close the transport immediately, without waiting for pending operations
to complete.  Buffered data will be lost.  No more data will be received.
The protocol&#8217;s <tt class="xref py py-meth docutils literal"><span class="pre">connection_lost()</span></tt> method will eventually be
called with <a class="reference internal" href="constants.html#None" title="None"><tt class="xref py py-const docutils literal"><span class="pre">None</span></tt></a> as its argument.</p>
</dd></dl>

</div>
<div class="section" id="basesubprocesstransport">
<h3>18.5.4.1.5. BaseSubprocessTransport<a class="headerlink" href="#basesubprocesstransport" title="Permalink to this headline">¶</a></h3>
<dl class="class">
<dt id="asyncio.BaseSubprocessTransport">
<em class="property">class </em><tt class="descclassname">asyncio.</tt><tt class="descname">BaseSubprocessTransport</tt><a class="headerlink" href="#asyncio.BaseSubprocessTransport" title="Permalink to this definition">¶</a></dt>
<dd><dl class="method">
<dt id="asyncio.BaseSubprocessTransport.get_pid">
<tt class="descname">get_pid</tt><big>(</big><big>)</big><a class="headerlink" href="#asyncio.BaseSubprocessTransport.get_pid" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the subprocess process id as an integer.</p>
</dd></dl>

<dl class="method">
<dt id="asyncio.BaseSubprocessTransport.get_pipe_transport">
<tt class="descname">get_pipe_transport</tt><big>(</big><em>fd</em><big>)</big><a class="headerlink" href="#asyncio.BaseSubprocessTransport.get_pipe_transport" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the transport for the communication pipe corresponding to the
integer file descriptor <em>fd</em>:</p>
<ul class="simple">
<li><tt class="docutils literal"><span class="pre">0</span></tt>: readable streaming transport of the standard input (<em>stdin</em>),
or <a class="reference internal" href="constants.html#None" title="None"><tt class="xref py py-const docutils literal"><span class="pre">None</span></tt></a> if the subprocess was not created with <tt class="docutils literal"><span class="pre">stdin=PIPE</span></tt></li>
<li><tt class="docutils literal"><span class="pre">1</span></tt>: writable streaming transport of the standard output (<em>stdout</em>),
or <a class="reference internal" href="constants.html#None" title="None"><tt class="xref py py-const docutils literal"><span class="pre">None</span></tt></a> if the subprocess was not created with <tt class="docutils literal"><span class="pre">stdout=PIPE</span></tt></li>
<li><tt class="docutils literal"><span class="pre">2</span></tt>: writable streaming transport of the standard error (<em>stderr</em>),
or <a class="reference internal" href="constants.html#None" title="None"><tt class="xref py py-const docutils literal"><span class="pre">None</span></tt></a> if the subprocess was not created with <tt class="docutils literal"><span class="pre">stderr=PIPE</span></tt></li>
<li>other <em>fd</em>: <a class="reference internal" href="constants.html#None" title="None"><tt class="xref py py-const docutils literal"><span class="pre">None</span></tt></a></li>
</ul>
</dd></dl>

<dl class="method">
<dt id="asyncio.BaseSubprocessTransport.get_returncode">
<tt class="descname">get_returncode</tt><big>(</big><big>)</big><a class="headerlink" href="#asyncio.BaseSubprocessTransport.get_returncode" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the subprocess returncode as an integer or <a class="reference internal" href="constants.html#None" title="None"><tt class="xref py py-const docutils literal"><span class="pre">None</span></tt></a>
if it hasn&#8217;t returned, similarly to the
<a class="reference internal" href="subprocess.html#subprocess.Popen.returncode" title="subprocess.Popen.returncode"><tt class="xref py py-attr docutils literal"><span class="pre">subprocess.Popen.returncode</span></tt></a> attribute.</p>
</dd></dl>

<dl class="method">
<dt id="asyncio.BaseSubprocessTransport.kill">
<tt class="descname">kill</tt><big>(</big><em>self</em><big>)</big><a class="headerlink" href="#asyncio.BaseSubprocessTransport.kill" title="Permalink to this definition">¶</a></dt>
<dd><p>Kill the subprocess, as in <a class="reference internal" href="subprocess.html#subprocess.Popen.kill" title="subprocess.Popen.kill"><tt class="xref py py-meth docutils literal"><span class="pre">subprocess.Popen.kill()</span></tt></a></p>
<p>On POSIX systems, the function sends SIGKILL to the subprocess.
On Windows, this method is an alias for <a class="reference internal" href="#asyncio.BaseSubprocessTransport.terminate" title="asyncio.BaseSubprocessTransport.terminate"><tt class="xref py py-meth docutils literal"><span class="pre">terminate()</span></tt></a>.</p>
</dd></dl>

<dl class="method">
<dt id="asyncio.BaseSubprocessTransport.send_signal">
<tt class="descname">send_signal</tt><big>(</big><em>signal</em><big>)</big><a class="headerlink" href="#asyncio.BaseSubprocessTransport.send_signal" title="Permalink to this definition">¶</a></dt>
<dd><p>Send the <em>signal</em> number to the subprocess, as in
<a class="reference internal" href="subprocess.html#subprocess.Popen.send_signal" title="subprocess.Popen.send_signal"><tt class="xref py py-meth docutils literal"><span class="pre">subprocess.Popen.send_signal()</span></tt></a>.</p>
</dd></dl>

<dl class="method">
<dt id="asyncio.BaseSubprocessTransport.terminate">
<tt class="descname">terminate</tt><big>(</big><big>)</big><a class="headerlink" href="#asyncio.BaseSubprocessTransport.terminate" title="Permalink to this definition">¶</a></dt>
<dd><p>Ask the subprocess to stop, as in <a class="reference internal" href="subprocess.html#subprocess.Popen.terminate" title="subprocess.Popen.terminate"><tt class="xref py py-meth docutils literal"><span class="pre">subprocess.Popen.terminate()</span></tt></a>.
This method is an alias for the <a class="reference internal" href="#asyncio.BaseSubprocessTransport.close" title="asyncio.BaseSubprocessTransport.close"><tt class="xref py py-meth docutils literal"><span class="pre">close()</span></tt></a> method.</p>
<p>On POSIX systems, this method sends SIGTERM to the subprocess.
On Windows, the Windows API function TerminateProcess() is called to
stop the subprocess.</p>
</dd></dl>

<dl class="method">
<dt id="asyncio.BaseSubprocessTransport.close">
<tt class="descname">close</tt><big>(</big><big>)</big><a class="headerlink" href="#asyncio.BaseSubprocessTransport.close" title="Permalink to this definition">¶</a></dt>
<dd><p>Ask the subprocess to stop by calling the <a class="reference internal" href="#asyncio.BaseSubprocessTransport.terminate" title="asyncio.BaseSubprocessTransport.terminate"><tt class="xref py py-meth docutils literal"><span class="pre">terminate()</span></tt></a> method if the
subprocess hasn&#8217;t returned yet, and close transports of all pipes
(<em>stdin</em>, <em>stdout</em> and <em>stderr</em>).</p>
</dd></dl>

</dd></dl>

</div>
</div>
<div class="section" id="protocols">
<span id="asyncio-protocol"></span><h2>18.5.4.2. Protocols<a class="headerlink" href="#protocols" title="Permalink to this headline">¶</a></h2>
<p><a class="reference internal" href="asyncio.html#module-asyncio" title="asyncio: Asynchronous I/O, event loop, coroutines and tasks."><tt class="xref py py-mod docutils literal"><span class="pre">asyncio</span></tt></a> provides base classes that you can subclass to implement
your network protocols.  Those classes are used in conjunction with
<a class="reference internal" href="#asyncio-transport"><em>transports</em></a> (see below): the protocol parses incoming
data and asks for the writing of outgoing data, while the transport is
responsible for the actual I/O and buffering.</p>
<p>When subclassing a protocol class, it is recommended you override certain
methods.  Those methods are callbacks: they will be called by the transport
on certain events (for example when some data is received); you shouldn&#8217;t
call them yourself, unless you are implementing a transport.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">All callbacks have default implementations, which are empty.  Therefore,
you only need to implement the callbacks for the events in which you
are interested.</p>
</div>
<div class="section" id="protocol-classes">
<h3>18.5.4.2.1. Protocol classes<a class="headerlink" href="#protocol-classes" title="Permalink to this headline">¶</a></h3>
<dl class="class">
<dt id="asyncio.Protocol">
<em class="property">class </em><tt class="descclassname">asyncio.</tt><tt class="descname">Protocol</tt><a class="headerlink" href="#asyncio.Protocol" title="Permalink to this definition">¶</a></dt>
<dd><p>The base class for implementing streaming protocols (for use with
e.g. TCP and SSL transports).</p>
</dd></dl>

<dl class="class">
<dt id="asyncio.DatagramProtocol">
<em class="property">class </em><tt class="descclassname">asyncio.</tt><tt class="descname">DatagramProtocol</tt><a class="headerlink" href="#asyncio.DatagramProtocol" title="Permalink to this definition">¶</a></dt>
<dd><p>The base class for implementing datagram protocols (for use with
e.g. UDP transports).</p>
</dd></dl>

<dl class="class">
<dt id="asyncio.SubprocessProtocol">
<em class="property">class </em><tt class="descclassname">asyncio.</tt><tt class="descname">SubprocessProtocol</tt><a class="headerlink" href="#asyncio.SubprocessProtocol" title="Permalink to this definition">¶</a></dt>
<dd><p>The base class for implementing protocols communicating with child
processes (through a set of unidirectional pipes).</p>
</dd></dl>

</div>
<div class="section" id="connection-callbacks">
<h3>18.5.4.2.2. Connection callbacks<a class="headerlink" href="#connection-callbacks" title="Permalink to this headline">¶</a></h3>
<p>These callbacks may be called on <a class="reference internal" href="#asyncio.Protocol" title="asyncio.Protocol"><tt class="xref py py-class docutils literal"><span class="pre">Protocol</span></tt></a>, <a class="reference internal" href="#asyncio.DatagramProtocol" title="asyncio.DatagramProtocol"><tt class="xref py py-class docutils literal"><span class="pre">DatagramProtocol</span></tt></a>
and <a class="reference internal" href="#asyncio.SubprocessProtocol" title="asyncio.SubprocessProtocol"><tt class="xref py py-class docutils literal"><span class="pre">SubprocessProtocol</span></tt></a> instances:</p>
<dl class="method">
<dt id="asyncio.BaseProtocol.connection_made">
<tt class="descclassname">BaseProtocol.</tt><tt class="descname">connection_made</tt><big>(</big><em>transport</em><big>)</big><a class="headerlink" href="#asyncio.BaseProtocol.connection_made" title="Permalink to this definition">¶</a></dt>
<dd><p>Called when a connection is made.</p>
<p>The <em>transport</em> argument is the transport representing the
connection.  You are responsible for storing it somewhere
(e.g. as an attribute) if you need to.</p>
</dd></dl>

<dl class="method">
<dt id="asyncio.BaseProtocol.connection_lost">
<tt class="descclassname">BaseProtocol.</tt><tt class="descname">connection_lost</tt><big>(</big><em>exc</em><big>)</big><a class="headerlink" href="#asyncio.BaseProtocol.connection_lost" title="Permalink to this definition">¶</a></dt>
<dd><p>Called when the connection is lost or closed.</p>
<p>The argument is either an exception object or <a class="reference internal" href="constants.html#None" title="None"><tt class="xref py py-const docutils literal"><span class="pre">None</span></tt></a>.
The latter means a regular EOF is received, or the connection was
aborted or closed by this side of the connection.</p>
</dd></dl>

<p><a class="reference internal" href="#asyncio.BaseProtocol.connection_made" title="asyncio.BaseProtocol.connection_made"><tt class="xref py py-meth docutils literal"><span class="pre">connection_made()</span></tt></a> and <a class="reference internal" href="#asyncio.BaseProtocol.connection_lost" title="asyncio.BaseProtocol.connection_lost"><tt class="xref py py-meth docutils literal"><span class="pre">connection_lost()</span></tt></a>
are called exactly once per successful connection.  All other callbacks will be
called between those two methods, which allows for easier resource management
in your protocol implementation.</p>
<p>The following callbacks may be called only on <a class="reference internal" href="#asyncio.SubprocessProtocol" title="asyncio.SubprocessProtocol"><tt class="xref py py-class docutils literal"><span class="pre">SubprocessProtocol</span></tt></a>
instances:</p>
<dl class="method">
<dt id="asyncio.SubprocessProtocol.pipe_data_received">
<tt class="descclassname">SubprocessProtocol.</tt><tt class="descname">pipe_data_received</tt><big>(</big><em>fd</em>, <em>data</em><big>)</big><a class="headerlink" href="#asyncio.SubprocessProtocol.pipe_data_received" title="Permalink to this definition">¶</a></dt>
<dd><p>Called when the child process writes data into its stdout or stderr pipe.
<em>fd</em> is the integer file descriptor of the pipe.  <em>data</em> is a non-empty
bytes object containing the data.</p>
</dd></dl>

<dl class="method">
<dt id="asyncio.SubprocessProtocol.pipe_connection_lost">
<tt class="descclassname">SubprocessProtocol.</tt><tt class="descname">pipe_connection_lost</tt><big>(</big><em>fd</em>, <em>exc</em><big>)</big><a class="headerlink" href="#asyncio.SubprocessProtocol.pipe_connection_lost" title="Permalink to this definition">¶</a></dt>
<dd><p>Called when one of the pipes communicating with the child process
is closed.  <em>fd</em> is the integer file descriptor that was closed.</p>
</dd></dl>

<dl class="method">
<dt id="asyncio.SubprocessProtocol.process_exited">
<tt class="descclassname">SubprocessProtocol.</tt><tt class="descname">process_exited</tt><big>(</big><big>)</big><a class="headerlink" href="#asyncio.SubprocessProtocol.process_exited" title="Permalink to this definition">¶</a></dt>
<dd><p>Called when the child process has exited.</p>
</dd></dl>

</div>
<div class="section" id="streaming-protocols">
<h3>18.5.4.2.3. Streaming protocols<a class="headerlink" href="#streaming-protocols" title="Permalink to this headline">¶</a></h3>
<p>The following callbacks are called on <a class="reference internal" href="#asyncio.Protocol" title="asyncio.Protocol"><tt class="xref py py-class docutils literal"><span class="pre">Protocol</span></tt></a> instances:</p>
<dl class="method">
<dt id="asyncio.Protocol.data_received">
<tt class="descclassname">Protocol.</tt><tt class="descname">data_received</tt><big>(</big><em>data</em><big>)</big><a class="headerlink" href="#asyncio.Protocol.data_received" title="Permalink to this definition">¶</a></dt>
<dd><p>Called when some data is received.  <em>data</em> is a non-empty bytes object
containing the incoming data.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Whether the data is buffered, chunked or reassembled depends on
the transport.  In general, you shouldn&#8217;t rely on specific semantics
and instead make your parsing generic and flexible enough.  However,
data is always received in the correct order.</p>
</div>
</dd></dl>

<dl class="method">
<dt id="asyncio.Protocol.eof_received">
<tt class="descclassname">Protocol.</tt><tt class="descname">eof_received</tt><big>(</big><big>)</big><a class="headerlink" href="#asyncio.Protocol.eof_received" title="Permalink to this definition">¶</a></dt>
<dd><p>Calls when the other end signals it won&#8217;t send any more data
(for example by calling <tt class="xref py py-meth docutils literal"><span class="pre">write_eof()</span></tt>, if the other end also uses
asyncio).</p>
<p>This method may return a false value (including None), in which case
the transport will close itself.  Conversely, if this method returns a
true value, closing the transport is up to the protocol.  Since the
default implementation returns None, it implicitly closes the connection.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Some transports such as SSL don&#8217;t support half-closed connections,
in which case returning true from this method will not prevent closing
the connection.</p>
</div>
</dd></dl>

<p><tt class="xref py py-meth docutils literal"><span class="pre">data_received()</span></tt> can be called an arbitrary number of times during
a connection.  However, <tt class="xref py py-meth docutils literal"><span class="pre">eof_received()</span></tt> is called at most once
and, if called, <tt class="xref py py-meth docutils literal"><span class="pre">data_received()</span></tt> won&#8217;t be called after it.</p>
<p>State machine:</p>
<blockquote>
<div>start -&gt; <a class="reference internal" href="#asyncio.BaseProtocol.connection_made" title="asyncio.BaseProtocol.connection_made"><tt class="xref py py-meth docutils literal"><span class="pre">connection_made()</span></tt></a>
[-&gt; <a class="reference internal" href="#asyncio.Protocol.data_received" title="asyncio.Protocol.data_received"><tt class="xref py py-meth docutils literal"><span class="pre">data_received()</span></tt></a> *]
[-&gt; <a class="reference internal" href="#asyncio.Protocol.eof_received" title="asyncio.Protocol.eof_received"><tt class="xref py py-meth docutils literal"><span class="pre">eof_received()</span></tt></a> ?]
-&gt; <a class="reference internal" href="#asyncio.BaseProtocol.connection_lost" title="asyncio.BaseProtocol.connection_lost"><tt class="xref py py-meth docutils literal"><span class="pre">connection_lost()</span></tt></a> -&gt; end</div></blockquote>
</div>
<div class="section" id="datagram-protocols">
<h3>18.5.4.2.4. Datagram protocols<a class="headerlink" href="#datagram-protocols" title="Permalink to this headline">¶</a></h3>
<p>The following callbacks are called on <a class="reference internal" href="#asyncio.DatagramProtocol" title="asyncio.DatagramProtocol"><tt class="xref py py-class docutils literal"><span class="pre">DatagramProtocol</span></tt></a> instances.</p>
<dl class="method">
<dt id="asyncio.DatagramProtocol.datagram_received">
<tt class="descclassname">DatagramProtocol.</tt><tt class="descname">datagram_received</tt><big>(</big><em>data</em>, <em>addr</em><big>)</big><a class="headerlink" href="#asyncio.DatagramProtocol.datagram_received" title="Permalink to this definition">¶</a></dt>
<dd><p>Called when a datagram is received.  <em>data</em> is a bytes object containing
the incoming data.  <em>addr</em> is the address of the peer sending the data;
the exact format depends on the transport.</p>
</dd></dl>

<dl class="method">
<dt id="asyncio.DatagramProtocol.error_received">
<tt class="descclassname">DatagramProtocol.</tt><tt class="descname">error_received</tt><big>(</big><em>exc</em><big>)</big><a class="headerlink" href="#asyncio.DatagramProtocol.error_received" title="Permalink to this definition">¶</a></dt>
<dd><p>Called when a previous send or receive operation raises an
<a class="reference internal" href="exceptions.html#OSError" title="OSError"><tt class="xref py py-class docutils literal"><span class="pre">OSError</span></tt></a>.  <em>exc</em> is the <a class="reference internal" href="exceptions.html#OSError" title="OSError"><tt class="xref py py-class docutils literal"><span class="pre">OSError</span></tt></a> instance.</p>
<p>This method is called in rare conditions, when the transport (e.g. UDP)
detects that a datagram couldn&#8217;t be delivered to its recipient.
In many conditions though, undeliverable datagrams will be silently
dropped.</p>
</dd></dl>

</div>
<div class="section" id="flow-control-callbacks">
<h3>18.5.4.2.5. Flow control callbacks<a class="headerlink" href="#flow-control-callbacks" title="Permalink to this headline">¶</a></h3>
<p>These callbacks may be called on <a class="reference internal" href="#asyncio.Protocol" title="asyncio.Protocol"><tt class="xref py py-class docutils literal"><span class="pre">Protocol</span></tt></a>,
<a class="reference internal" href="#asyncio.DatagramProtocol" title="asyncio.DatagramProtocol"><tt class="xref py py-class docutils literal"><span class="pre">DatagramProtocol</span></tt></a> and <a class="reference internal" href="#asyncio.SubprocessProtocol" title="asyncio.SubprocessProtocol"><tt class="xref py py-class docutils literal"><span class="pre">SubprocessProtocol</span></tt></a> instances:</p>
<dl class="method">
<dt id="asyncio.BaseProtocol.pause_writing">
<tt class="descclassname">BaseProtocol.</tt><tt class="descname">pause_writing</tt><big>(</big><big>)</big><a class="headerlink" href="#asyncio.BaseProtocol.pause_writing" title="Permalink to this definition">¶</a></dt>
<dd><p>Called when the transport&#8217;s buffer goes over the high-water mark.</p>
</dd></dl>

<dl class="method">
<dt id="asyncio.BaseProtocol.resume_writing">
<tt class="descclassname">BaseProtocol.</tt><tt class="descname">resume_writing</tt><big>(</big><big>)</big><a class="headerlink" href="#asyncio.BaseProtocol.resume_writing" title="Permalink to this definition">¶</a></dt>
<dd><p>Called when the transport&#8217;s buffer drains below the low-water mark.</p>
</dd></dl>

<p><tt class="xref py py-meth docutils literal"><span class="pre">pause_writing()</span></tt> and <tt class="xref py py-meth docutils literal"><span class="pre">resume_writing()</span></tt> calls are paired &#8211;
<tt class="xref py py-meth docutils literal"><span class="pre">pause_writing()</span></tt> is called once when the buffer goes strictly over
the high-water mark (even if subsequent writes increases the buffer size
even more), and eventually <tt class="xref py py-meth docutils literal"><span class="pre">resume_writing()</span></tt> is called once when the
buffer size reaches the low-water mark.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">If the buffer size equals the high-water mark,
<tt class="xref py py-meth docutils literal"><span class="pre">pause_writing()</span></tt> is not called &#8211; it must go strictly over.
Conversely, <tt class="xref py py-meth docutils literal"><span class="pre">resume_writing()</span></tt> is called when the buffer size is
equal or lower than the low-water mark.  These end conditions
are important to ensure that things go as expected when either
mark is zero.</p>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">On BSD systems (OS X, FreeBSD, etc.) flow control is not supported
for <a class="reference internal" href="#asyncio.DatagramProtocol" title="asyncio.DatagramProtocol"><tt class="xref py py-class docutils literal"><span class="pre">DatagramProtocol</span></tt></a>, because send failures caused by
writing too many packets cannot be detected easily.  The socket
always appears &#8216;ready&#8217; and excess packets are dropped; an
<a class="reference internal" href="exceptions.html#OSError" title="OSError"><tt class="xref py py-class docutils literal"><span class="pre">OSError</span></tt></a> with errno set to <a class="reference internal" href="errno.html#errno.ENOBUFS" title="errno.ENOBUFS"><tt class="xref py py-const docutils literal"><span class="pre">errno.ENOBUFS</span></tt></a> may or
may not be raised; if it is raised, it will be reported to
<a class="reference internal" href="#asyncio.DatagramProtocol.error_received" title="asyncio.DatagramProtocol.error_received"><tt class="xref py py-meth docutils literal"><span class="pre">DatagramProtocol.error_received()</span></tt></a> but otherwise ignored.</p>
</div>
</div>
<div class="section" id="coroutines-and-protocols">
<h3>18.5.4.2.6. Coroutines and protocols<a class="headerlink" href="#coroutines-and-protocols" title="Permalink to this headline">¶</a></h3>
<p>Coroutines can be scheduled in a protocol method using <a class="reference internal" href="asyncio-task.html#asyncio.async" title="asyncio.async"><tt class="xref py py-func docutils literal"><span class="pre">async()</span></tt></a>, but there
is no guarantee made about the execution order.  Protocols are not aware of
coroutines created in protocol methods and so will not wait for them.</p>
<p>To have a reliable execution order, use <a class="reference internal" href="asyncio-stream.html#asyncio-streams"><em>stream objects</em></a> in a
coroutine with <tt class="docutils literal"><span class="pre">yield</span> <span class="pre">from</span></tt>. For example, the <a class="reference internal" href="asyncio-stream.html#asyncio.StreamWriter.drain" title="asyncio.StreamWriter.drain"><tt class="xref py py-meth docutils literal"><span class="pre">StreamWriter.drain()</span></tt></a>
coroutine can be used to wait until the write buffer is flushed.</p>
</div>
</div>
<div class="section" id="protocol-examples">
<h2>18.5.4.3. Protocol examples<a class="headerlink" href="#protocol-examples" title="Permalink to this headline">¶</a></h2>
<div class="section" id="tcp-echo-client-protocol">
<span id="asyncio-tcp-echo-client-protocol"></span><h3>18.5.4.3.1. TCP echo client protocol<a class="headerlink" href="#tcp-echo-client-protocol" title="Permalink to this headline">¶</a></h3>
<p>TCP echo client  using the <a class="reference internal" href="asyncio-eventloop.html#asyncio.BaseEventLoop.create_connection" title="asyncio.BaseEventLoop.create_connection"><tt class="xref py py-meth docutils literal"><span class="pre">BaseEventLoop.create_connection()</span></tt></a> method, send
data and wait until the connection is closed:</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">asyncio</span>

<span class="k">class</span> <span class="nc">EchoClientProtocol</span><span class="p">(</span><span class="n">asyncio</span><span class="o">.</span><span class="n">Protocol</span><span class="p">):</span>
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">,</span> <span class="n">loop</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">message</span> <span class="o">=</span> <span class="n">message</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">loop</span> <span class="o">=</span> <span class="n">loop</span>

    <span class="k">def</span> <span class="nf">connection_made</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">transport</span><span class="p">):</span>
        <span class="n">transport</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">message</span><span class="o">.</span><span class="n">encode</span><span class="p">())</span>
        <span class="nb">print</span><span class="p">(</span><span class="s">&#39;Data sent: {!r}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">message</span><span class="p">))</span>

    <span class="k">def</span> <span class="nf">data_received</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
        <span class="nb">print</span><span class="p">(</span><span class="s">&#39;Data received: {!r}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">decode</span><span class="p">()))</span>

    <span class="k">def</span> <span class="nf">connection_lost</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">exc</span><span class="p">):</span>
        <span class="nb">print</span><span class="p">(</span><span class="s">&#39;The server closed the connection&#39;</span><span class="p">)</span>
        <span class="nb">print</span><span class="p">(</span><span class="s">&#39;Stop the event lop&#39;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">loop</span><span class="o">.</span><span class="n">stop</span><span class="p">()</span>

<span class="n">loop</span> <span class="o">=</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">get_event_loop</span><span class="p">()</span>
<span class="n">message</span> <span class="o">=</span> <span class="s">&#39;Hello World!&#39;</span>
<span class="n">coro</span> <span class="o">=</span> <span class="n">loop</span><span class="o">.</span><span class="n">create_connection</span><span class="p">(</span><span class="k">lambda</span><span class="p">:</span> <span class="n">EchoClientProtocol</span><span class="p">(</span><span class="n">message</span><span class="p">,</span> <span class="n">loop</span><span class="p">),</span>
                              <span class="s">&#39;127.0.0.1&#39;</span><span class="p">,</span> <span class="mi">8888</span><span class="p">)</span>
<span class="n">loop</span><span class="o">.</span><span class="n">run_until_complete</span><span class="p">(</span><span class="n">coro</span><span class="p">)</span>
<span class="n">loop</span><span class="o">.</span><span class="n">run_forever</span><span class="p">()</span>
<span class="n">loop</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
</pre></div>
</div>
<p>The event loop is running twice. The
<a class="reference internal" href="asyncio-eventloop.html#asyncio.BaseEventLoop.run_until_complete" title="asyncio.BaseEventLoop.run_until_complete"><tt class="xref py py-meth docutils literal"><span class="pre">run_until_complete()</span></tt></a> method is preferred in this short
example to raise an exception if the server is not listening, instead of
having to write a short coroutine to handle the exception and stop the
running loop. At <a class="reference internal" href="asyncio-eventloop.html#asyncio.BaseEventLoop.run_until_complete" title="asyncio.BaseEventLoop.run_until_complete"><tt class="xref py py-meth docutils literal"><span class="pre">run_until_complete()</span></tt></a> exit, the loop is
no longer running, so there is no need to stop the loop in case of an error.</p>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last">The <a class="reference internal" href="asyncio-stream.html#asyncio-tcp-echo-client-streams"><em>TCP echo client using streams</em></a>
example uses the <a class="reference internal" href="asyncio-stream.html#asyncio.open_connection" title="asyncio.open_connection"><tt class="xref py py-func docutils literal"><span class="pre">asyncio.open_connection()</span></tt></a> function.</p>
</div>
</div>
<div class="section" id="tcp-echo-server-protocol">
<span id="asyncio-tcp-echo-server-protocol"></span><h3>18.5.4.3.2. TCP echo server protocol<a class="headerlink" href="#tcp-echo-server-protocol" title="Permalink to this headline">¶</a></h3>
<p>TCP echo server using the <a class="reference internal" href="asyncio-eventloop.html#asyncio.BaseEventLoop.create_server" title="asyncio.BaseEventLoop.create_server"><tt class="xref py py-meth docutils literal"><span class="pre">BaseEventLoop.create_server()</span></tt></a> method, send back
received data and close the connection:</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">asyncio</span>

<span class="k">class</span> <span class="nc">EchoServerClientProtocol</span><span class="p">(</span><span class="n">asyncio</span><span class="o">.</span><span class="n">Protocol</span><span class="p">):</span>
    <span class="k">def</span> <span class="nf">connection_made</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">transport</span><span class="p">):</span>
        <span class="n">peername</span> <span class="o">=</span> <span class="n">transport</span><span class="o">.</span><span class="n">get_extra_info</span><span class="p">(</span><span class="s">&#39;peername&#39;</span><span class="p">)</span>
        <span class="nb">print</span><span class="p">(</span><span class="s">&#39;Connection from {}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">peername</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">transport</span> <span class="o">=</span> <span class="n">transport</span>

    <span class="k">def</span> <span class="nf">data_received</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
        <span class="n">message</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">decode</span><span class="p">()</span>
        <span class="nb">print</span><span class="p">(</span><span class="s">&#39;Data received: {!r}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">message</span><span class="p">))</span>

        <span class="nb">print</span><span class="p">(</span><span class="s">&#39;Send: {!r}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">message</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">transport</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>

        <span class="nb">print</span><span class="p">(</span><span class="s">&#39;Close the client socket&#39;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">transport</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>

<span class="n">loop</span> <span class="o">=</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">get_event_loop</span><span class="p">()</span>
<span class="c"># Each client connection will create a new protocol instance</span>
<span class="n">coro</span> <span class="o">=</span> <span class="n">loop</span><span class="o">.</span><span class="n">create_server</span><span class="p">(</span><span class="n">EchoServerClientProtocol</span><span class="p">,</span> <span class="s">&#39;127.0.0.1&#39;</span><span class="p">,</span> <span class="mi">8888</span><span class="p">)</span>
<span class="n">server</span> <span class="o">=</span> <span class="n">loop</span><span class="o">.</span><span class="n">run_until_complete</span><span class="p">(</span><span class="n">coro</span><span class="p">)</span>

<span class="c"># Serve requests until CTRL+c is pressed</span>
<span class="nb">print</span><span class="p">(</span><span class="s">&#39;Serving on {}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">server</span><span class="o">.</span><span class="n">sockets</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">getsockname</span><span class="p">()))</span>
<span class="k">try</span><span class="p">:</span>
    <span class="n">loop</span><span class="o">.</span><span class="n">run_forever</span><span class="p">()</span>
<span class="k">except</span> <span class="ne">KeyboardInterrupt</span><span class="p">:</span>
    <span class="k">pass</span>

<span class="c"># Close the server</span>
<span class="n">server</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
<span class="n">loop</span><span class="o">.</span><span class="n">run_until_complete</span><span class="p">(</span><span class="n">server</span><span class="o">.</span><span class="n">wait_closed</span><span class="p">())</span>
<span class="n">loop</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
</pre></div>
</div>
<p><tt class="xref py py-meth docutils literal"><span class="pre">Transport.close()</span></tt> can be called immediately after
<a class="reference internal" href="#asyncio.WriteTransport.write" title="asyncio.WriteTransport.write"><tt class="xref py py-meth docutils literal"><span class="pre">WriteTransport.write()</span></tt></a> even if data are not sent yet on the socket: both
methods are asynchronous. <tt class="docutils literal"><span class="pre">yield</span> <span class="pre">from</span></tt> is not needed because these transport
methods are not coroutines.</p>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last">The <a class="reference internal" href="asyncio-stream.html#asyncio-tcp-echo-server-streams"><em>TCP echo server using streams</em></a>
example uses the <a class="reference internal" href="asyncio-stream.html#asyncio.start_server" title="asyncio.start_server"><tt class="xref py py-func docutils literal"><span class="pre">asyncio.start_server()</span></tt></a> function.</p>
</div>
</div>
<div class="section" id="udp-echo-client-protocol">
<span id="asyncio-udp-echo-client-protocol"></span><h3>18.5.4.3.3. UDP echo client protocol<a class="headerlink" href="#udp-echo-client-protocol" title="Permalink to this headline">¶</a></h3>
<p>UDP echo client using the <a class="reference internal" href="asyncio-eventloop.html#asyncio.BaseEventLoop.create_datagram_endpoint" title="asyncio.BaseEventLoop.create_datagram_endpoint"><tt class="xref py py-meth docutils literal"><span class="pre">BaseEventLoop.create_datagram_endpoint()</span></tt></a>
method, send data and close the transport when we received the answer:</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">asyncio</span>

<span class="k">class</span> <span class="nc">EchoClientProtocol</span><span class="p">:</span>
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">,</span> <span class="n">loop</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">message</span> <span class="o">=</span> <span class="n">message</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">loop</span> <span class="o">=</span> <span class="n">loop</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">transport</span> <span class="o">=</span> <span class="k">None</span>

    <span class="k">def</span> <span class="nf">connection_made</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">transport</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">transport</span> <span class="o">=</span> <span class="n">transport</span>
        <span class="nb">print</span><span class="p">(</span><span class="s">&#39;Send:&#39;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">message</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">transport</span><span class="o">.</span><span class="n">sendto</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">message</span><span class="o">.</span><span class="n">encode</span><span class="p">())</span>

    <span class="k">def</span> <span class="nf">datagram_received</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">addr</span><span class="p">):</span>
        <span class="nb">print</span><span class="p">(</span><span class="s">&quot;Received:&quot;</span><span class="p">,</span> <span class="n">data</span><span class="o">.</span><span class="n">decode</span><span class="p">())</span>

        <span class="nb">print</span><span class="p">(</span><span class="s">&quot;Close the socket&quot;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">transport</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>

    <span class="k">def</span> <span class="nf">error_received</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">exc</span><span class="p">):</span>
        <span class="nb">print</span><span class="p">(</span><span class="s">&#39;Error received:&#39;</span><span class="p">,</span> <span class="n">exc</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">connection_lost</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">exc</span><span class="p">):</span>
        <span class="nb">print</span><span class="p">(</span><span class="s">&quot;Socket closed, stop the event loop&quot;</span><span class="p">)</span>
        <span class="n">loop</span> <span class="o">=</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">get_event_loop</span><span class="p">()</span>
        <span class="n">loop</span><span class="o">.</span><span class="n">stop</span><span class="p">()</span>

<span class="n">loop</span> <span class="o">=</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">get_event_loop</span><span class="p">()</span>
<span class="n">message</span> <span class="o">=</span> <span class="s">&quot;Hello World!&quot;</span>
<span class="n">connect</span> <span class="o">=</span> <span class="n">loop</span><span class="o">.</span><span class="n">create_datagram_endpoint</span><span class="p">(</span>
    <span class="k">lambda</span><span class="p">:</span> <span class="n">EchoClientProtocol</span><span class="p">(</span><span class="n">message</span><span class="p">,</span> <span class="n">loop</span><span class="p">),</span>
    <span class="n">remote_addr</span><span class="o">=</span><span class="p">(</span><span class="s">&#39;127.0.0.1&#39;</span><span class="p">,</span> <span class="mi">9999</span><span class="p">))</span>
<span class="n">transport</span><span class="p">,</span> <span class="n">protocol</span> <span class="o">=</span> <span class="n">loop</span><span class="o">.</span><span class="n">run_until_complete</span><span class="p">(</span><span class="n">connect</span><span class="p">)</span>
<span class="n">loop</span><span class="o">.</span><span class="n">run_forever</span><span class="p">()</span>
<span class="n">transport</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
<span class="n">loop</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
</pre></div>
</div>
</div>
<div class="section" id="udp-echo-server-protocol">
<span id="asyncio-udp-echo-server-protocol"></span><h3>18.5.4.3.4. UDP echo server protocol<a class="headerlink" href="#udp-echo-server-protocol" title="Permalink to this headline">¶</a></h3>
<p>UDP echo server using the <a class="reference internal" href="asyncio-eventloop.html#asyncio.BaseEventLoop.create_datagram_endpoint" title="asyncio.BaseEventLoop.create_datagram_endpoint"><tt class="xref py py-meth docutils literal"><span class="pre">BaseEventLoop.create_datagram_endpoint()</span></tt></a>
method, send back received data:</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">asyncio</span>

<span class="k">class</span> <span class="nc">EchoServerProtocol</span><span class="p">:</span>
    <span class="k">def</span> <span class="nf">connection_made</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">transport</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">transport</span> <span class="o">=</span> <span class="n">transport</span>

    <span class="k">def</span> <span class="nf">datagram_received</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">addr</span><span class="p">):</span>
        <span class="n">message</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">decode</span><span class="p">()</span>
        <span class="nb">print</span><span class="p">(</span><span class="s">&#39;Received %r from %s&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">message</span><span class="p">,</span> <span class="n">addr</span><span class="p">))</span>
        <span class="nb">print</span><span class="p">(</span><span class="s">&#39;Send %r to %s&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">message</span><span class="p">,</span> <span class="n">addr</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">transport</span><span class="o">.</span><span class="n">sendto</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">addr</span><span class="p">)</span>

<span class="n">loop</span> <span class="o">=</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">get_event_loop</span><span class="p">()</span>
<span class="nb">print</span><span class="p">(</span><span class="s">&quot;Starting UDP server&quot;</span><span class="p">)</span>
<span class="c"># One protocol instance will be created to serve all client requests</span>
<span class="n">listen</span> <span class="o">=</span> <span class="n">loop</span><span class="o">.</span><span class="n">create_datagram_endpoint</span><span class="p">(</span>
    <span class="n">EchoServerProtocol</span><span class="p">,</span> <span class="n">local_addr</span><span class="o">=</span><span class="p">(</span><span class="s">&#39;127.0.0.1&#39;</span><span class="p">,</span> <span class="mi">9999</span><span class="p">))</span>
<span class="n">transport</span><span class="p">,</span> <span class="n">protocol</span> <span class="o">=</span> <span class="n">loop</span><span class="o">.</span><span class="n">run_until_complete</span><span class="p">(</span><span class="n">listen</span><span class="p">)</span>

<span class="k">try</span><span class="p">:</span>
    <span class="n">loop</span><span class="o">.</span><span class="n">run_forever</span><span class="p">()</span>
<span class="k">except</span> <span class="ne">KeyboardInterrupt</span><span class="p">:</span>
    <span class="k">pass</span>

<span class="n">transport</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
<span class="n">loop</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
</pre></div>
</div>
</div>
<div class="section" id="register-an-open-socket-to-wait-for-data-using-a-protocol">
<span id="asyncio-register-socket"></span><h3>18.5.4.3.5. Register an open socket to wait for data using a protocol<a class="headerlink" href="#register-an-open-socket-to-wait-for-data-using-a-protocol" title="Permalink to this headline">¶</a></h3>
<p>Wait until a socket receives data using the
<a class="reference internal" href="asyncio-eventloop.html#asyncio.BaseEventLoop.create_connection" title="asyncio.BaseEventLoop.create_connection"><tt class="xref py py-meth docutils literal"><span class="pre">BaseEventLoop.create_connection()</span></tt></a> method with a protocol, and then close
the event loop</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">asyncio</span>
<span class="k">try</span><span class="p">:</span>
    <span class="kn">from</span> <span class="nn">socket</span> <span class="k">import</span> <span class="n">socketpair</span>
<span class="k">except</span> <span class="ne">ImportError</span><span class="p">:</span>
    <span class="kn">from</span> <span class="nn">asyncio.windows_utils</span> <span class="k">import</span> <span class="n">socketpair</span>

<span class="c"># Create a pair of connected sockets</span>
<span class="n">rsock</span><span class="p">,</span> <span class="n">wsock</span> <span class="o">=</span> <span class="n">socketpair</span><span class="p">()</span>
<span class="n">loop</span> <span class="o">=</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">get_event_loop</span><span class="p">()</span>

<span class="k">class</span> <span class="nc">MyProtocol</span><span class="p">(</span><span class="n">asyncio</span><span class="o">.</span><span class="n">Protocol</span><span class="p">):</span>
    <span class="n">transport</span> <span class="o">=</span> <span class="k">None</span>

    <span class="k">def</span> <span class="nf">connection_made</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">transport</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">transport</span> <span class="o">=</span> <span class="n">transport</span>

    <span class="k">def</span> <span class="nf">data_received</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
        <span class="nb">print</span><span class="p">(</span><span class="s">&quot;Received:&quot;</span><span class="p">,</span> <span class="n">data</span><span class="o">.</span><span class="n">decode</span><span class="p">())</span>

        <span class="c"># We are done: close the transport (it will call connection_lost())</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">transport</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>

    <span class="k">def</span> <span class="nf">connection_lost</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">exc</span><span class="p">):</span>
        <span class="c"># The socket has been closed, stop the event loop</span>
        <span class="n">loop</span><span class="o">.</span><span class="n">stop</span><span class="p">()</span>

<span class="c"># Register the socket to wait for data</span>
<span class="n">connect_coro</span> <span class="o">=</span> <span class="n">loop</span><span class="o">.</span><span class="n">create_connection</span><span class="p">(</span><span class="n">MyProtocol</span><span class="p">,</span> <span class="n">sock</span><span class="o">=</span><span class="n">rsock</span><span class="p">)</span>
<span class="n">transport</span><span class="p">,</span> <span class="n">protocol</span> <span class="o">=</span> <span class="n">loop</span><span class="o">.</span><span class="n">run_until_complete</span><span class="p">(</span><span class="n">connect_coro</span><span class="p">)</span>

<span class="c"># Simulate the reception of data from the network</span>
<span class="n">loop</span><span class="o">.</span><span class="n">call_soon</span><span class="p">(</span><span class="n">wsock</span><span class="o">.</span><span class="n">send</span><span class="p">,</span> <span class="s">&#39;abc&#39;</span><span class="o">.</span><span class="n">encode</span><span class="p">())</span>

<span class="c"># Run the event loop</span>
<span class="n">loop</span><span class="o">.</span><span class="n">run_forever</span><span class="p">()</span>

<span class="c"># We are done, close sockets and the event loop</span>
<span class="n">rsock</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
<span class="n">wsock</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
<span class="n">loop</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p>The <a class="reference internal" href="asyncio-eventloop.html#asyncio-watch-read-event"><em>watch a file descriptor for read events</em></a> example uses the low-level
<a class="reference internal" href="asyncio-eventloop.html#asyncio.BaseEventLoop.add_reader" title="asyncio.BaseEventLoop.add_reader"><tt class="xref py py-meth docutils literal"><span class="pre">BaseEventLoop.add_reader()</span></tt></a> method to register the file descriptor of a
socket.</p>
<p class="last">The <a class="reference internal" href="asyncio-stream.html#asyncio-register-socket-streams"><em>register an open socket to wait for data using streams</em></a> example uses high-level streams
created by the <a class="reference internal" href="asyncio-stream.html#asyncio.open_connection" title="asyncio.open_connection"><tt class="xref py py-func docutils literal"><span class="pre">open_connection()</span></tt></a> function in a coroutine.</p>
</div>
</div>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../contents.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">18.5.4. Transports  and protocols (low-level API)</a><ul>
<li><a class="reference internal" href="#transports">18.5.4.1. Transports</a><ul>
<li><a class="reference internal" href="#basetransport">18.5.4.1.1. BaseTransport</a></li>
<li><a class="reference internal" href="#readtransport">18.5.4.1.2. ReadTransport</a></li>
<li><a class="reference internal" href="#writetransport">18.5.4.1.3. WriteTransport</a></li>
<li><a class="reference internal" href="#datagramtransport">18.5.4.1.4. DatagramTransport</a></li>
<li><a class="reference internal" href="#basesubprocesstransport">18.5.4.1.5. BaseSubprocessTransport</a></li>
</ul>
</li>
<li><a class="reference internal" href="#protocols">18.5.4.2. Protocols</a><ul>
<li><a class="reference internal" href="#protocol-classes">18.5.4.2.1. Protocol classes</a></li>
<li><a class="reference internal" href="#connection-callbacks">18.5.4.2.2. Connection callbacks</a></li>
<li><a class="reference internal" href="#streaming-protocols">18.5.4.2.3. Streaming protocols</a></li>
<li><a class="reference internal" href="#datagram-protocols">18.5.4.2.4. Datagram protocols</a></li>
<li><a class="reference internal" href="#flow-control-callbacks">18.5.4.2.5. Flow control callbacks</a></li>
<li><a class="reference internal" href="#coroutines-and-protocols">18.5.4.2.6. Coroutines and protocols</a></li>
</ul>
</li>
<li><a class="reference internal" href="#protocol-examples">18.5.4.3. Protocol examples</a><ul>
<li><a class="reference internal" href="#tcp-echo-client-protocol">18.5.4.3.1. TCP echo client protocol</a></li>
<li><a class="reference internal" href="#tcp-echo-server-protocol">18.5.4.3.2. TCP echo server protocol</a></li>
<li><a class="reference internal" href="#udp-echo-client-protocol">18.5.4.3.3. UDP echo client protocol</a></li>
<li><a class="reference internal" href="#udp-echo-server-protocol">18.5.4.3.4. UDP echo server protocol</a></li>
<li><a class="reference internal" href="#register-an-open-socket-to-wait-for-data-using-a-protocol">18.5.4.3.5. Register an open socket to wait for data using a protocol</a></li>
</ul>
</li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="asyncio-task.html"
                        title="previous chapter">18.5.3. Tasks and coroutines</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="asyncio-stream.html"
                        title="next chapter">18.5.5. Streams (high-level API)</a></p>
<h3>This Page</h3>
<ul class="this-page-menu">
  <li><a href="../bugs.html">Report a Bug</a></li>
  <li><a href="../_sources/library/asyncio-protocol.txt"
         rel="nofollow">Show Source</a></li>
</ul>

<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>  
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="asyncio-stream.html" title="18.5.5. Streams (high-level API)"
             >next</a> |</li>
        <li class="right" >
          <a href="asyncio-task.html" title="18.5.3. Tasks and coroutines"
             >previous</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="https://www.python.org/">Python</a> &raquo;</li>
        <li>
          <a href="../index.html">3.4.3 Documentation</a> &raquo;
        </li>

          <li><a href="index.html" >The Python Standard Library</a> &raquo;</li>
          <li><a href="ipc.html" >18. Interprocess Communication and Networking</a> &raquo;</li>
          <li><a href="asyncio.html" >18.5. <tt class="docutils literal"><span class="pre">asyncio</span></tt> &#8211; Asynchronous I/O, event loop, coroutines and tasks</a> &raquo;</li> 
      </ul>
    </div>  
    <div class="footer">
    &copy; <a href="../copyright.html">Copyright</a> 1990-2015, Python Software Foundation.
    <br />
    The Python Software Foundation is a non-profit corporation.
    <a href="https://www.python.org/psf/donations/">Please donate.</a>
    <br />
    Last updated on Feb 25, 2015.
    <a href="../bugs.html">Found a bug</a>?
    <br />
    Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.2.3.
    </div>

  </body>
</html>

@KyuuKazami