{{+bindTo:partials.standard_nacl_api}}
<h1>pp::TCPSocket Class Reference</h1>
<div id="doxygen-ref">
{{- dummy div to appease doxygen -}}
<div>
<!-- Generated by Doxygen 1.7.6.1 -->
</div>
<!--header-->
<div class="contents">
<!-- doxytag: class="pp::TCPSocket" --><!-- doxytag: inherits="pp::Resource" --><div class="dynheader">
Inheritance diagram for pp::TCPSocket:</div>
<div class="dyncontent">
<div class="center"><img src="classpp_1_1_t_c_p_socket__inherit__graph.png" border="0" usemap="#pp_1_1_t_c_p_socket_inherit__map" alt="Inheritance graph" /></div>
<map name="pp_1_1_t_c_p_socket_inherit__map" id="pp_1_1_t_c_p_socket_inherit__map">
<area shape="rect" id="node2" href="classpp_1_1_resource.html" title="A reference counted module resource." alt="" coords="9,5,113,32"></area></map>
<center><span class="legend">[<a href="graph_legend.html">legend</a>]</span></center></div>
<p><a href="classpp_1_1_t_c_p_socket-members.html">List of all members.</a></p>
<h2>
Public Member Functions</h2><table class="memberdecls">
<tr><td class="memItemLeft" align="right" valign="top"> </td><td class="memItemRight" valign="bottom"><a class="el" href="classpp_1_1_t_c_p_socket.html#a8752f9c331ea25e01bf4a80be95117ef">TCPSocket</a> ()</td></tr>
<tr><td class="memItemLeft" align="right" valign="top"> </td><td class="memItemRight" valign="bottom"><a class="el" href="classpp_1_1_t_c_p_socket.html#af33619315cc5eeff15174a78b0fff44d">TCPSocket</a> (const <a class="el" href="classpp_1_1_instance_handle.html">InstanceHandle</a> &instance)</td></tr>
<tr><td class="memItemLeft" align="right" valign="top"> </td><td class="memItemRight" valign="bottom"><a class="el" href="classpp_1_1_t_c_p_socket.html#aa7af4b57237e461a79ba33e044d688fe">TCPSocket</a> (<a class="el" href="namespacepp.html#a339083c1beec620267bf8b3c55decaa5">PassRef</a>, PP_Resource resource)</td></tr>
<tr><td class="memItemLeft" align="right" valign="top"> </td><td class="memItemRight" valign="bottom"><a class="el" href="classpp_1_1_t_c_p_socket.html#a528305852766af8c12284e6ef7e94058">TCPSocket</a> (const <a class="el" href="classpp_1_1_t_c_p_socket.html">TCPSocket</a> &other)</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">virtual </td><td class="memItemRight" valign="bottom"><a class="el" href="classpp_1_1_t_c_p_socket.html#a32547904059796aa6def4c9ab6107c80">~TCPSocket</a> ()</td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="el" href="classpp_1_1_t_c_p_socket.html">TCPSocket</a> & </td><td class="memItemRight" valign="bottom"><a class="el" href="classpp_1_1_t_c_p_socket.html#ae7c8888a8f6ef5187547de8b8db3bb98">operator=</a> (const <a class="el" href="classpp_1_1_t_c_p_socket.html">TCPSocket</a> &other)</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">int32_t </td><td class="memItemRight" valign="bottom"><a class="el" href="classpp_1_1_t_c_p_socket.html#a266c28928c7524fa8bad8bca513c8f2b">Bind</a> (const <a class="el" href="classpp_1_1_net_address.html">NetAddress</a> &addr, const <a class="el" href="classpp_1_1_completion_callback.html">CompletionCallback</a> &callback)</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">int32_t </td><td class="memItemRight" valign="bottom"><a class="el" href="classpp_1_1_t_c_p_socket.html#a939f7d319a58c60afcb71f6356223aac">Connect</a> (const <a class="el" href="classpp_1_1_net_address.html">NetAddress</a> &addr, const <a class="el" href="classpp_1_1_completion_callback.html">CompletionCallback</a> &callback)</td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="el" href="classpp_1_1_net_address.html">NetAddress</a> </td><td class="memItemRight" valign="bottom"><a class="el" href="classpp_1_1_t_c_p_socket.html#ad35bf6762cac2eceb4469eba0275ed7f">GetLocalAddress</a> () const </td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="el" href="classpp_1_1_net_address.html">NetAddress</a> </td><td class="memItemRight" valign="bottom"><a class="el" href="classpp_1_1_t_c_p_socket.html#a6d8c7d3ab135c58f0cd92202946c1ea8">GetRemoteAddress</a> () const </td></tr>
<tr><td class="memItemLeft" align="right" valign="top">int32_t </td><td class="memItemRight" valign="bottom"><a class="el" href="classpp_1_1_t_c_p_socket.html#a598efe777f0ef2eb9117b11437e1bedb">Read</a> (char *buffer, int32_t bytes_to_read, const <a class="el" href="classpp_1_1_completion_callback.html">CompletionCallback</a> &callback)</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">int32_t </td><td class="memItemRight" valign="bottom"><a class="el" href="classpp_1_1_t_c_p_socket.html#aef066de742e7271ca72fa8e4e177f63b">Write</a> (const char *buffer, int32_t bytes_to_write, const <a class="el" href="classpp_1_1_completion_callback.html">CompletionCallback</a> &callback)</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">int32_t </td><td class="memItemRight" valign="bottom"><a class="el" href="classpp_1_1_t_c_p_socket.html#afed8c462e80b265b132a53e8cbd87fbb">Listen</a> (int32_t backlog, const <a class="el" href="classpp_1_1_completion_callback.html">CompletionCallback</a> &callback)</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">int32_t </td><td class="memItemRight" valign="bottom"><a class="el" href="classpp_1_1_t_c_p_socket.html#aef5daadffa0cf98464d30c418f1eceb1">Accept</a> (const <a class="el" href="classpp_1_1_completion_callback_with_output.html">CompletionCallbackWithOutput</a>< <a class="el" href="classpp_1_1_t_c_p_socket.html">TCPSocket</a> > &callback)</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="classpp_1_1_t_c_p_socket.html#abc186103df13872795525a65ab48a478">Close</a> ()</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">int32_t </td><td class="memItemRight" valign="bottom"><a class="el" href="classpp_1_1_t_c_p_socket.html#a71fdfb61f8ab4fbc805bb66b34a77484">SetOption</a> (PP_TCPSocket_Option name, const <a class="el" href="classpp_1_1_var.html">Var</a> &value, const <a class="el" href="classpp_1_1_completion_callback.html">CompletionCallback</a> &callback)</td></tr>
</table><h2>
Static Public Member Functions</h2><table class="memberdecls">
<tr><td class="memItemLeft" align="right" valign="top">static bool </td><td class="memItemRight" valign="bottom"><a class="el" href="classpp_1_1_t_c_p_socket.html#addc35d01f8547e3128358c401a2a8e47">IsAvailable</a> ()</td></tr>
</table>
<hr /><a name="details" id="details"></a><h2>Detailed Description</h2>
<div class="textblock"><p>The <code><a class="el" href="classpp_1_1_t_c_p_socket.html" title="The TCPSocket class provides TCP socket operations.">TCPSocket</a></code> class provides TCP socket operations. </p>
<p>Permissions: Apps permission <code>socket</code> with subrule <code>tcp-connect</code> is required for <code><a class="el" href="classpp_1_1_t_c_p_socket.html#a939f7d319a58c60afcb71f6356223aac" title="Connects the socket to the given address.">Connect()</a></code>; subrule <code>tcp-listen</code> is required for <code><a class="el" href="classpp_1_1_t_c_p_socket.html#afed8c462e80b265b132a53e8cbd87fbb" title="Starts listening.">Listen()</a></code>. For more details about network communication permissions, please see: <a href="http://developer.chrome.com/apps/app_network.html">http://developer.chrome.com/apps/app_network.html</a> </p>
</div><hr /><h2>Constructor & Destructor Documentation</h2>
<a class="anchor" id="a8752f9c331ea25e01bf4a80be95117ef"></a><!-- doxytag: member="pp::TCPSocket::TCPSocket" ref="a8752f9c331ea25e01bf4a80be95117ef" args="()" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname"><a class="el" href="classpp_1_1_t_c_p_socket.html#a8752f9c331ea25e01bf4a80be95117ef">pp::TCPSocket::TCPSocket</a> </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>Default constructor for creating an <a class="el" href="classpp_1_1_resource.html#a859068e34cdc2dc0b78754c255323aa9" title="This functions determines if this resource is invalid or uninitialized.">is_null()</a> <code><a class="el" href="classpp_1_1_t_c_p_socket.html" title="The TCPSocket class provides TCP socket operations.">TCPSocket</a></code> object. </p>
</div>
</div>
<a class="anchor" id="af33619315cc5eeff15174a78b0fff44d"></a><!-- doxytag: member="pp::TCPSocket::TCPSocket" ref="af33619315cc5eeff15174a78b0fff44d" args="(const InstanceHandle &instance)" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname"><a class="el" href="classpp_1_1_t_c_p_socket.html#a8752f9c331ea25e01bf4a80be95117ef">pp::TCPSocket::TCPSocket</a> </td>
<td>(</td>
<td class="paramtype">const <a class="el" href="classpp_1_1_instance_handle.html">InstanceHandle</a> & </td>
<td class="paramname"><em>instance</em></td><td>)</td>
<td><code> [explicit]</code></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>A constructor used to create a <code><a class="el" href="classpp_1_1_t_c_p_socket.html" title="The TCPSocket class provides TCP socket operations.">TCPSocket</a></code> object. </p>
<dl class="params"><dt><b>Parameters:</b></dt><dd>
<table class="params">
<tr><td class="paramdir">[in]</td><td class="paramname">instance</td><td>The instance with which this resource will be associated. </td></tr>
</table>
</dd>
</dl>
</div>
</div>
<a class="anchor" id="aa7af4b57237e461a79ba33e044d688fe"></a><!-- doxytag: member="pp::TCPSocket::TCPSocket" ref="aa7af4b57237e461a79ba33e044d688fe" args="(PassRef, PP_Resource resource)" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname"><a class="el" href="classpp_1_1_t_c_p_socket.html#a8752f9c331ea25e01bf4a80be95117ef">pp::TCPSocket::TCPSocket</a> </td>
<td>(</td>
<td class="paramtype"><a class="el" href="namespacepp.html#a339083c1beec620267bf8b3c55decaa5">PassRef</a> </td>
<td class="paramname">, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">PP_Resource </td>
<td class="paramname"><em>resource</em> </td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>A constructor used when you have received a <code>PP_Resource</code> as a return value that has had 1 ref added for you. </p>
<dl class="params"><dt><b>Parameters:</b></dt><dd>
<table class="params">
<tr><td class="paramdir">[in]</td><td class="paramname">resource</td><td>A <code>PPB_TCPSocket</code> resource. </td></tr>
</table>
</dd>
</dl>
</div>
</div>
<a class="anchor" id="a528305852766af8c12284e6ef7e94058"></a><!-- doxytag: member="pp::TCPSocket::TCPSocket" ref="a528305852766af8c12284e6ef7e94058" args="(const TCPSocket &other)" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname"><a class="el" href="classpp_1_1_t_c_p_socket.html#a8752f9c331ea25e01bf4a80be95117ef">pp::TCPSocket::TCPSocket</a> </td>
<td>(</td>
<td class="paramtype">const <a class="el" href="classpp_1_1_t_c_p_socket.html">TCPSocket</a> & </td>
<td class="paramname"><em>other</em></td><td>)</td>
<td></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>The copy constructor for <code><a class="el" href="classpp_1_1_t_c_p_socket.html" title="The TCPSocket class provides TCP socket operations.">TCPSocket</a></code>. </p>
<dl class="params"><dt><b>Parameters:</b></dt><dd>
<table class="params">
<tr><td class="paramdir">[in]</td><td class="paramname">other</td><td>A reference to another <code><a class="el" href="classpp_1_1_t_c_p_socket.html" title="The TCPSocket class provides TCP socket operations.">TCPSocket</a></code>. </td></tr>
</table>
</dd>
</dl>
</div>
</div>
<a class="anchor" id="a32547904059796aa6def4c9ab6107c80"></a><!-- doxytag: member="pp::TCPSocket::~TCPSocket" ref="a32547904059796aa6def4c9ab6107c80" args="()" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">virtual <a class="el" href="classpp_1_1_t_c_p_socket.html#a32547904059796aa6def4c9ab6107c80">pp::TCPSocket::~TCPSocket</a> </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td><code> [virtual]</code></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>The destructor. </p>
</div>
</div>
<hr /><h2>Member Function Documentation</h2>
<a class="anchor" id="aef5daadffa0cf98464d30c418f1eceb1"></a><!-- doxytag: member="pp::TCPSocket::Accept" ref="aef5daadffa0cf98464d30c418f1eceb1" args="(const CompletionCallbackWithOutput< TCPSocket > &callback)" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">int32_t <a class="el" href="classpp_1_1_t_c_p_socket.html#aef5daadffa0cf98464d30c418f1eceb1">pp::TCPSocket::Accept</a> </td>
<td>(</td>
<td class="paramtype">const <a class="el" href="classpp_1_1_completion_callback_with_output.html">CompletionCallbackWithOutput</a>< <a class="el" href="classpp_1_1_t_c_p_socket.html">TCPSocket</a> > & </td>
<td class="paramname"><em>callback</em></td><td>)</td>
<td></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>Accepts a connection. </p>
<p>The socket must be listening.</p>
<dl class="params"><dt><b>Parameters:</b></dt><dd>
<table class="params">
<tr><td class="paramdir">[in]</td><td class="paramname">callback</td><td>A <code><a class="el" href="classpp_1_1_completion_callback_with_output.html" title="A CompletionCallbackWithOutput defines a completion callback that additionally stores a pointer to so...">CompletionCallbackWithOutput</a></code> to be called upon completion.</td></tr>
</table>
</dd>
</dl>
<dl class="return"><dt><b>Returns:</b></dt><dd>An int32_t containing an error code from <code>pp_errors.h</code>, including (but not limited to):<ul>
<li><code>PP_ERROR_CONNECTION_ABORTED</code>: A connection has been aborted. </li>
</ul>
</dd></dl>
</div>
</div>
<a class="anchor" id="a266c28928c7524fa8bad8bca513c8f2b"></a><!-- doxytag: member="pp::TCPSocket::Bind" ref="a266c28928c7524fa8bad8bca513c8f2b" args="(const NetAddress &addr, const CompletionCallback &callback)" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">int32_t <a class="el" href="classpp_1_1_t_c_p_socket.html#a266c28928c7524fa8bad8bca513c8f2b">pp::TCPSocket::Bind</a> </td>
<td>(</td>
<td class="paramtype">const <a class="el" href="classpp_1_1_net_address.html">NetAddress</a> & </td>
<td class="paramname"><em>addr</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">const <a class="el" href="classpp_1_1_completion_callback.html">CompletionCallback</a> & </td>
<td class="paramname"><em>callback</em> </td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>Binds the socket to the given address. </p>
<p>The socket must not be bound.</p>
<dl class="params"><dt><b>Parameters:</b></dt><dd>
<table class="params">
<tr><td class="paramdir">[in]</td><td class="paramname">addr</td><td>A <code><a class="el" href="classpp_1_1_net_address.html" title="The NetAddress class represents a network address.">NetAddress</a></code> object. </td></tr>
<tr><td class="paramdir">[in]</td><td class="paramname">callback</td><td>A <code><a class="el" href="classpp_1_1_completion_callback.html" title="This API enables you to implement and receive callbacks when Pepper operations complete asynchronousl...">CompletionCallback</a></code> to be called upon completion.</td></tr>
</table>
</dd>
</dl>
<dl class="return"><dt><b>Returns:</b></dt><dd>An int32_t containing an error code from <code>pp_errors.h</code>, including (but not limited to):<ul>
<li><code>PP_ERROR_ADDRESS_IN_USE</code>: the address is already in use.</li>
<li><code>PP_ERROR_ADDRESS_INVALID</code>: the address is invalid. </li>
</ul>
</dd></dl>
</div>
</div>
<a class="anchor" id="abc186103df13872795525a65ab48a478"></a><!-- doxytag: member="pp::TCPSocket::Close" ref="abc186103df13872795525a65ab48a478" args="()" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void <a class="el" href="classpp_1_1_t_c_p_socket.html#abc186103df13872795525a65ab48a478">pp::TCPSocket::Close</a> </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>Cancels all pending operations and closes the socket. </p>
<p>Any pending callbacks will still run, reporting <code>PP_ERROR_ABORTED</code> if pending IO was interrupted. After a call to this method, no output buffer pointers passed into previous <code><a class="el" href="classpp_1_1_t_c_p_socket.html#a598efe777f0ef2eb9117b11437e1bedb" title="Reads data from the socket.">Read()</a></code> or <code><a class="el" href="classpp_1_1_t_c_p_socket.html#aef5daadffa0cf98464d30c418f1eceb1" title="Accepts a connection.">Accept()</a></code> calls will be accessed. It is not valid to call <code><a class="el" href="classpp_1_1_t_c_p_socket.html#a939f7d319a58c60afcb71f6356223aac" title="Connects the socket to the given address.">Connect()</a></code> or <code><a class="el" href="classpp_1_1_t_c_p_socket.html#afed8c462e80b265b132a53e8cbd87fbb" title="Starts listening.">Listen()</a></code> again.</p>
<p>The socket is implicitly closed if it is destroyed, so you are not required to call this method. </p>
</div>
</div>
<a class="anchor" id="a939f7d319a58c60afcb71f6356223aac"></a><!-- doxytag: member="pp::TCPSocket::Connect" ref="a939f7d319a58c60afcb71f6356223aac" args="(const NetAddress &addr, const CompletionCallback &callback)" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">int32_t <a class="el" href="classpp_1_1_t_c_p_socket.html#a939f7d319a58c60afcb71f6356223aac">pp::TCPSocket::Connect</a> </td>
<td>(</td>
<td class="paramtype">const <a class="el" href="classpp_1_1_net_address.html">NetAddress</a> & </td>
<td class="paramname"><em>addr</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">const <a class="el" href="classpp_1_1_completion_callback.html">CompletionCallback</a> & </td>
<td class="paramname"><em>callback</em> </td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>Connects the socket to the given address. </p>
<p>The socket must not be listening. Binding the socket beforehand is optional.</p>
<dl class="params"><dt><b>Parameters:</b></dt><dd>
<table class="params">
<tr><td class="paramdir">[in]</td><td class="paramname">addr</td><td>A <code><a class="el" href="classpp_1_1_net_address.html" title="The NetAddress class represents a network address.">NetAddress</a></code> object. </td></tr>
<tr><td class="paramdir">[in]</td><td class="paramname">callback</td><td>A <code><a class="el" href="classpp_1_1_completion_callback.html" title="This API enables you to implement and receive callbacks when Pepper operations complete asynchronousl...">CompletionCallback</a></code> to be called upon completion.</td></tr>
</table>
</dd>
</dl>
<dl class="return"><dt><b>Returns:</b></dt><dd>An int32_t containing an error code from <code>pp_errors.h</code>, including (but not limited to):<ul>
<li><code>PP_ERROR_NOACCESS</code>: the caller doesn't have required permissions.</li>
<li><code>PP_ERROR_ADDRESS_UNREACHABLE</code>: <code>addr</code> is unreachable.</li>
<li><code>PP_ERROR_CONNECTION_REFUSED</code>: the connection attempt was refused.</li>
<li><code>PP_ERROR_CONNECTION_FAILED</code>: the connection attempt failed.</li>
<li><code>PP_ERROR_CONNECTION_TIMEDOUT</code>: the connection attempt timed out.</li>
</ul>
</dd></dl>
<p>Since version 1.1, if the socket is listening/connected or has a pending listen/connect request, <code><a class="el" href="classpp_1_1_t_c_p_socket.html#a939f7d319a58c60afcb71f6356223aac" title="Connects the socket to the given address.">Connect()</a></code> will fail without starting a connection attempt. Otherwise, any failure during the connection attempt will cause the socket to be closed. </p>
</div>
</div>
<a class="anchor" id="ad35bf6762cac2eceb4469eba0275ed7f"></a><!-- doxytag: member="pp::TCPSocket::GetLocalAddress" ref="ad35bf6762cac2eceb4469eba0275ed7f" args="() const " -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname"><a class="el" href="classpp_1_1_net_address.html">NetAddress</a> <a class="el" href="classpp_1_1_t_c_p_socket.html#ad35bf6762cac2eceb4469eba0275ed7f">pp::TCPSocket::GetLocalAddress</a> </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td> const</td>
</tr>
</table>
</div>
<div class="memdoc">
<p>Gets the local address of the socket, if it is bound. </p>
<dl class="return"><dt><b>Returns:</b></dt><dd>A <code><a class="el" href="classpp_1_1_net_address.html" title="The NetAddress class represents a network address.">NetAddress</a></code> object. The object will be null (i.e., <a class="el" href="classpp_1_1_resource.html#a859068e34cdc2dc0b78754c255323aa9" title="This functions determines if this resource is invalid or uninitialized.">is_null()</a> returns true) on failure. </dd></dl>
</div>
</div>
<a class="anchor" id="a6d8c7d3ab135c58f0cd92202946c1ea8"></a><!-- doxytag: member="pp::TCPSocket::GetRemoteAddress" ref="a6d8c7d3ab135c58f0cd92202946c1ea8" args="() const " -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname"><a class="el" href="classpp_1_1_net_address.html">NetAddress</a> <a class="el" href="classpp_1_1_t_c_p_socket.html#a6d8c7d3ab135c58f0cd92202946c1ea8">pp::TCPSocket::GetRemoteAddress</a> </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td> const</td>
</tr>
</table>
</div>
<div class="memdoc">
<p>Gets the remote address of the socket, if it is connected. </p>
<dl class="return"><dt><b>Returns:</b></dt><dd>A <code><a class="el" href="classpp_1_1_net_address.html" title="The NetAddress class represents a network address.">NetAddress</a></code> object. The object will be null (i.e., <a class="el" href="classpp_1_1_resource.html#a859068e34cdc2dc0b78754c255323aa9" title="This functions determines if this resource is invalid or uninitialized.">is_null()</a> returns true) on failure. </dd></dl>
</div>
</div>
<a class="anchor" id="addc35d01f8547e3128358c401a2a8e47"></a><!-- doxytag: member="pp::TCPSocket::IsAvailable" ref="addc35d01f8547e3128358c401a2a8e47" args="()" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">static bool <a class="el" href="classpp_1_1_t_c_p_socket.html#addc35d01f8547e3128358c401a2a8e47">pp::TCPSocket::IsAvailable</a> </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td><code> [static]</code></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>Static function for determining whether the browser supports the <code>PPB_TCPSocket</code> interface. </p>
<dl class="return"><dt><b>Returns:</b></dt><dd>true if the interface is available, false otherwise. </dd></dl>
</div>
</div>
<a class="anchor" id="afed8c462e80b265b132a53e8cbd87fbb"></a><!-- doxytag: member="pp::TCPSocket::Listen" ref="afed8c462e80b265b132a53e8cbd87fbb" args="(int32_t backlog, const CompletionCallback &callback)" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">int32_t <a class="el" href="classpp_1_1_t_c_p_socket.html#afed8c462e80b265b132a53e8cbd87fbb">pp::TCPSocket::Listen</a> </td>
<td>(</td>
<td class="paramtype">int32_t </td>
<td class="paramname"><em>backlog</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">const <a class="el" href="classpp_1_1_completion_callback.html">CompletionCallback</a> & </td>
<td class="paramname"><em>callback</em> </td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>Starts listening. </p>
<p>The socket must be bound and not connected.</p>
<dl class="params"><dt><b>Parameters:</b></dt><dd>
<table class="params">
<tr><td class="paramdir">[in]</td><td class="paramname">backlog</td><td>A hint to determine the maximum length to which the queue of pending connections may grow. </td></tr>
<tr><td class="paramdir">[in]</td><td class="paramname">callback</td><td>A <code><a class="el" href="classpp_1_1_completion_callback.html" title="This API enables you to implement and receive callbacks when Pepper operations complete asynchronousl...">CompletionCallback</a></code> to be called upon completion.</td></tr>
</table>
</dd>
</dl>
<dl class="return"><dt><b>Returns:</b></dt><dd>An int32_t containing an error code from <code>pp_errors.h</code>, including (but not limited to):<ul>
<li><code>PP_ERROR_NOACCESS</code>: the caller doesn't have required permissions.</li>
<li><code>PP_ERROR_ADDRESS_IN_USE</code>: Another socket is already listening on the same port. </li>
</ul>
</dd></dl>
</div>
</div>
<a class="anchor" id="ae7c8888a8f6ef5187547de8b8db3bb98"></a><!-- doxytag: member="pp::TCPSocket::operator=" ref="ae7c8888a8f6ef5187547de8b8db3bb98" args="(const TCPSocket &other)" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname"><a class="el" href="classpp_1_1_t_c_p_socket.html">TCPSocket</a>& pp::TCPSocket::operator= </td>
<td>(</td>
<td class="paramtype">const <a class="el" href="classpp_1_1_t_c_p_socket.html">TCPSocket</a> & </td>
<td class="paramname"><em>other</em></td><td>)</td>
<td></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>The assignment operator for <code><a class="el" href="classpp_1_1_t_c_p_socket.html" title="The TCPSocket class provides TCP socket operations.">TCPSocket</a></code>. </p>
<dl class="params"><dt><b>Parameters:</b></dt><dd>
<table class="params">
<tr><td class="paramdir">[in]</td><td class="paramname">other</td><td>A reference to another <code><a class="el" href="classpp_1_1_t_c_p_socket.html" title="The TCPSocket class provides TCP socket operations.">TCPSocket</a></code>.</td></tr>
</table>
</dd>
</dl>
<dl class="return"><dt><b>Returns:</b></dt><dd>A reference to this <code><a class="el" href="classpp_1_1_t_c_p_socket.html" title="The TCPSocket class provides TCP socket operations.">TCPSocket</a></code> object. </dd></dl>
</div>
</div>
<a class="anchor" id="a598efe777f0ef2eb9117b11437e1bedb"></a><!-- doxytag: member="pp::TCPSocket::Read" ref="a598efe777f0ef2eb9117b11437e1bedb" args="(char *buffer, int32_t bytes_to_read, const CompletionCallback &callback)" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">int32_t <a class="el" href="classpp_1_1_t_c_p_socket.html#a598efe777f0ef2eb9117b11437e1bedb">pp::TCPSocket::Read</a> </td>
<td>(</td>
<td class="paramtype">char * </td>
<td class="paramname"><em>buffer</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">int32_t </td>
<td class="paramname"><em>bytes_to_read</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">const <a class="el" href="classpp_1_1_completion_callback.html">CompletionCallback</a> & </td>
<td class="paramname"><em>callback</em> </td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>Reads data from the socket. </p>
<p>The socket must be connected. It may perform a partial read.</p>
<p><b>Caveat:</b> You should be careful about the lifetime of <code>buffer</code>. Typically you will use a <code><a class="el" href="classpp_1_1_completion_callback_factory.html" title="CompletionCallbackFactory<T> may be used to create CompletionCallback objects that are bound to membe...">CompletionCallbackFactory</a></code> to scope callbacks to the lifetime of your class. When your class goes out of scope, the callback factory will not actually cancel the operation, but will rather just skip issuing the callback on your class. This means that if the underlying <code>PPB_TCPSocket</code> resource outlives your class, the browser will still try to write into your buffer when the operation completes. The buffer must be kept valid until then to avoid memory corruption. If you want to release the buffer while the <code><a class="el" href="classpp_1_1_t_c_p_socket.html#a598efe777f0ef2eb9117b11437e1bedb" title="Reads data from the socket.">Read()</a></code> call is still pending, you should call <code><a class="el" href="classpp_1_1_t_c_p_socket.html#abc186103df13872795525a65ab48a478" title="Cancels all pending operations and closes the socket.">Close()</a></code> to ensure that the buffer won't be accessed in the future.</p>
<dl class="params"><dt><b>Parameters:</b></dt><dd>
<table class="params">
<tr><td class="paramdir">[out]</td><td class="paramname">buffer</td><td>The buffer to store the received data on success. It must be at least as large as <code>bytes_to_read</code>. </td></tr>
<tr><td class="paramdir">[in]</td><td class="paramname">bytes_to_read</td><td>The number of bytes to read. </td></tr>
<tr><td class="paramdir">[in]</td><td class="paramname">callback</td><td>A <code><a class="el" href="classpp_1_1_completion_callback.html" title="This API enables you to implement and receive callbacks when Pepper operations complete asynchronousl...">CompletionCallback</a></code> to be called upon completion.</td></tr>
</table>
</dd>
</dl>
<dl class="return"><dt><b>Returns:</b></dt><dd>A non-negative number on success to indicate how many bytes have been read, 0 means that end-of-file was reached; otherwise, an error code from <code>pp_errors.h</code>. </dd></dl>
</div>
</div>
<a class="anchor" id="a71fdfb61f8ab4fbc805bb66b34a77484"></a><!-- doxytag: member="pp::TCPSocket::SetOption" ref="a71fdfb61f8ab4fbc805bb66b34a77484" args="(PP_TCPSocket_Option name, const Var &value, const CompletionCallback &callback)" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">int32_t <a class="el" href="classpp_1_1_t_c_p_socket.html#a71fdfb61f8ab4fbc805bb66b34a77484">pp::TCPSocket::SetOption</a> </td>
<td>(</td>
<td class="paramtype">PP_TCPSocket_Option </td>
<td class="paramname"><em>name</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">const <a class="el" href="classpp_1_1_var.html">Var</a> & </td>
<td class="paramname"><em>value</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">const <a class="el" href="classpp_1_1_completion_callback.html">CompletionCallback</a> & </td>
<td class="paramname"><em>callback</em> </td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>Sets a socket option on the TCP socket. </p>
<p>Please see the <code>PP_TCPSocket_Option</code> description for option names, value types and allowed values.</p>
<dl class="params"><dt><b>Parameters:</b></dt><dd>
<table class="params">
<tr><td class="paramdir">[in]</td><td class="paramname">name</td><td>The option to set. </td></tr>
<tr><td class="paramdir">[in]</td><td class="paramname">value</td><td>The option value to set. </td></tr>
<tr><td class="paramdir">[in]</td><td class="paramname">callback</td><td>A <code><a class="el" href="classpp_1_1_completion_callback.html" title="This API enables you to implement and receive callbacks when Pepper operations complete asynchronousl...">CompletionCallback</a></code> to be called upon completion.</td></tr>
</table>
</dd>
</dl>
<dl class="return"><dt><b>Returns:</b></dt><dd>An int32_t containing an error code from <code>pp_errors.h</code>. </dd></dl>
</div>
</div>
<a class="anchor" id="aef066de742e7271ca72fa8e4e177f63b"></a><!-- doxytag: member="pp::TCPSocket::Write" ref="aef066de742e7271ca72fa8e4e177f63b" args="(const char *buffer, int32_t bytes_to_write, const CompletionCallback &callback)" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">int32_t <a class="el" href="classpp_1_1_t_c_p_socket.html#aef066de742e7271ca72fa8e4e177f63b">pp::TCPSocket::Write</a> </td>
<td>(</td>
<td class="paramtype">const char * </td>
<td class="paramname"><em>buffer</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">int32_t </td>
<td class="paramname"><em>bytes_to_write</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">const <a class="el" href="classpp_1_1_completion_callback.html">CompletionCallback</a> & </td>
<td class="paramname"><em>callback</em> </td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>Writes data to the socket. </p>
<p>The socket must be connected. It may perform a partial write.</p>
<dl class="params"><dt><b>Parameters:</b></dt><dd>
<table class="params">
<tr><td class="paramdir">[in]</td><td class="paramname">buffer</td><td>The buffer containing the data to write. </td></tr>
<tr><td class="paramdir">[in]</td><td class="paramname">bytes_to_write</td><td>The number of bytes to write. </td></tr>
<tr><td class="paramdir">[in]</td><td class="paramname">callback</td><td>A <code><a class="el" href="classpp_1_1_completion_callback.html" title="This API enables you to implement and receive callbacks when Pepper operations complete asynchronousl...">CompletionCallback</a></code> to be called upon completion.</td></tr>
</table>
</dd>
</dl>
<dl class="return"><dt><b>Returns:</b></dt><dd>A non-negative number on success to indicate how many bytes have been written; otherwise, an error code from <code>pp_errors.h</code>. </dd></dl>
</div>
</div>
<hr />The documentation for this class was generated from the following file:<ul>
<li><a class="el" href="tcp__socket_8h.html">tcp_socket.h</a></li>
</ul>
</div><!-- contents -->
</div>
{{/partials.standard_nacl_api}}