<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Module ranch_tcp</title> <link rel="stylesheet" type="text/css" href="stylesheet.css" title="EDoc"> </head> <body bgcolor="white"> <div class="navbar"><a name="#navbar_top"></a><table width="100%" border="0" cellspacing="0" cellpadding="2" summary="navigation bar"><tr><td><a href="overview-summary.html" target="overviewFrame">Overview</a></td><td><a href="http://www.erlang.org/"><img src="erlang.png" align="right" border="0" alt="erlang logo"></a></td></tr></table></div> <hr> <h1>Module ranch_tcp</h1> <ul class="index"><li><a href="#description">Description</a></li><li><a href="#index">Function Index</a></li><li><a href="#functions">Function Details</a></li></ul>TCP transport API. <p><b>Behaviours:</b> <a href="ranch_transport.html"><tt>ranch_transport</tt></a>.</p> <p><b>See also:</b> <a href="gen_tcp.html">gen_tcp</a>.</p> <h2><a name="description">Description</a></h2><p>TCP transport API.</p> Wrapper around <em>gen_tcp</em> implementing the Ranch transport API. <h2><a name="index">Function Index</a></h2> <table width="100%" border="1" cellspacing="0" cellpadding="2" summary="function index"><tr><td valign="top"><a href="#accept-2">accept/2</a></td><td>Accept connections with the given listening socket.</td></tr> <tr><td valign="top"><a href="#close-1">close/1</a></td><td>Close the given socket.</td></tr> <tr><td valign="top"><a href="#controlling_process-2">controlling_process/2</a></td><td>Give control of the socket to a new process.</td></tr> <tr><td valign="top"><a href="#listen-1">listen/1</a></td><td>Listen for connections on the given port number.</td></tr> <tr><td valign="top"><a href="#messages-0">messages/0</a></td><td>Atoms used to identify messages in {active, once | true} mode.</td></tr> <tr><td valign="top"><a href="#name-0">name/0</a></td><td>Name of this transport, <em>tcp</em>.</td></tr> <tr><td valign="top"><a href="#peername-1">peername/1</a></td><td>Return the remote address and port of the connection.</td></tr> <tr><td valign="top"><a href="#recv-3">recv/3</a></td><td>Receive data from a socket in passive mode.</td></tr> <tr><td valign="top"><a href="#send-2">send/2</a></td><td>Send data on a socket.</td></tr> <tr><td valign="top"><a href="#sendfile-2">sendfile/2</a></td><td>Send a file on a socket.</td></tr> <tr><td valign="top"><a href="#setopts-2">setopts/2</a></td><td>Set options on the given socket.</td></tr> <tr><td valign="top"><a href="#sockname-1">sockname/1</a></td><td>Return the local address and port of the connection.</td></tr> </table> <h2><a name="functions">Function Details</a></h2> <h3 class="function"><a name="accept-2">accept/2</a></h3> <div class="spec"> <p><tt>accept(LSocket::<a href="inet.html#type-socket">inet:socket()</a>, Timeout::timeout()) -> {ok, <a href="inet.html#type-socket">inet:socket()</a>} | {error, closed | timeout | atom()}</tt><br></p> </div><p>Accept connections with the given listening socket.</p> <p><b>See also:</b> <a href="gen_tcp.html#accept-2">gen_tcp:accept/2</a>.</p> <h3 class="function"><a name="close-1">close/1</a></h3> <div class="spec"> <p><tt>close(Socket::<a href="inet.html#type-socket">inet:socket()</a>) -> ok</tt><br></p> </div><p>Close the given socket.</p> <p><b>See also:</b> <a href="gen_tcp.html#close-1">gen_tcp:close/1</a>.</p> <h3 class="function"><a name="controlling_process-2">controlling_process/2</a></h3> <div class="spec"> <p><tt>controlling_process(Socket::<a href="inet.html#type-socket">inet:socket()</a>, Pid::pid()) -> ok | {error, closed | not_owner | atom()}</tt><br></p> </div><p><p>Give control of the socket to a new process.</p> Must be called from the process currently controlling the socket, otherwise an {error, not_owner} tuple will be returned. </p> <p><b>See also:</b> <a href="gen_tcp.html#controlling_process-2">gen_tcp:controlling_process/2</a>.</p> <h3 class="function"><a name="listen-1">listen/1</a></h3> <div class="spec"> <p><tt>listen(Opts::[{backlog, non_neg_integer()} | {ip, <a href="inet.html#type-ip_address">inet:ip_address()</a>} | {nodelay, boolean()} | {port, <a href="inet.html#type-port_number">inet:port_number()</a>}]) -> {ok, <a href="inet.html#type-socket">inet:socket()</a>} | {error, atom()}</tt><br></p> </div><p><p>Listen for connections on the given port number.</p> <p>Calling this function returns a listening socket that can then be passed to accept/2 to accept connections.</p> The available options are: <dl> <dt>backlog</dt><dd>Maximum length of the pending connections queue. Defaults to 1024.</dd> <dt>ip</dt><dd>Interface to listen on. Listen on all interfaces by default.</dd> <dt>nodelay</dt><dd>Optional. Enable TCP_NODELAY. Enabled by default.</dd> <dt>port</dt><dd>TCP port number to open. Defaults to 0 (see below).</dd> </dl> You can listen to a random port by setting the port option to 0. It is then possible to retrieve this port number by calling sockname/1 on the listening socket. If you are using Ranch's listener API, then this port number can obtained through ranch:get_port/1 instead. </p> <p><b>See also:</b> <a href="gen_tcp.html#listen-2">gen_tcp:listen/2</a>.</p> <h3 class="function"><a name="messages-0">messages/0</a></h3> <div class="spec"> <p><tt>messages() -> any()</tt></p> </div><p>Atoms used to identify messages in {active, once | true} mode.</p> <h3 class="function"><a name="name-0">name/0</a></h3> <div class="spec"> <p><tt>name() -> any()</tt></p> </div><p>Name of this transport, <em>tcp</em>.</p> <h3 class="function"><a name="peername-1">peername/1</a></h3> <div class="spec"> <p><tt>peername(Socket::<a href="inet.html#type-socket">inet:socket()</a>) -> {ok, {<a href="inet.html#type-ip_address">inet:ip_address()</a>, <a href="inet.html#type-port_number">inet:port_number()</a>}} | {error, atom()}</tt><br></p> </div><p>Return the remote address and port of the connection.</p> <p><b>See also:</b> <a href="inet.html#peername-1">inet:peername/1</a>.</p> <h3 class="function"><a name="recv-3">recv/3</a></h3> <div class="spec"> <p><tt>recv(Socket::<a href="inet.html#type-socket">inet:socket()</a>, Length::non_neg_integer(), Timeout::timeout()) -> {ok, any()} | {error, closed | atom()}</tt><br></p> </div><p>Receive data from a socket in passive mode.</p> <p><b>See also:</b> <a href="gen_tcp.html#recv-3">gen_tcp:recv/3</a>.</p> <h3 class="function"><a name="send-2">send/2</a></h3> <div class="spec"> <p><tt>send(Socket::<a href="inet.html#type-socket">inet:socket()</a>, Packet::iodata()) -> ok | {error, atom()}</tt><br></p> </div><p>Send data on a socket.</p> <p><b>See also:</b> <a href="gen_tcp.html#send-2">gen_tcp:send/2</a>.</p> <h3 class="function"><a name="sendfile-2">sendfile/2</a></h3> <div class="spec"> <p><tt>sendfile(Socket::<a href="inet.html#type-socket">inet:socket()</a>, Filename::<a href="file.html#type-name">file:name()</a>) -> {ok, non_neg_integer()} | {error, atom()}</tt><br></p> </div><p><p>Send a file on a socket.</p> This is the optimal way to send files using TCP. It uses a syscall which means there is no context switch between opening the file and writing its contents on the socket. </p> <p><b>See also:</b> <a href="file.html#sendfile-2">file:sendfile/2</a>.</p> <h3 class="function"><a name="setopts-2">setopts/2</a></h3> <div class="spec"> <p><tt>setopts(Socket::<a href="inet.html#type-socket">inet:socket()</a>, Opts::list()) -> ok | {error, atom()}</tt><br></p> </div><p>Set options on the given socket.</p> <p><b>See also:</b> <a href="inet.html#setopts-2">inet:setopts/2</a>.</p> <h3 class="function"><a name="sockname-1">sockname/1</a></h3> <div class="spec"> <p><tt>sockname(Socket::<a href="inet.html#type-socket">inet:socket()</a>) -> {ok, {<a href="inet.html#type-ip_address">inet:ip_address()</a>, <a href="inet.html#type-port_number">inet:port_number()</a>}} | {error, atom()}</tt><br></p> </div><p>Return the local address and port of the connection.</p> <p><b>See also:</b> <a href="inet.html#sockname-1">inet:sockname/1</a>.</p> <hr> <div class="navbar"><a name="#navbar_bottom"></a><table width="100%" border="0" cellspacing="0" cellpadding="2" summary="navigation bar"><tr><td><a href="overview-summary.html" target="overviewFrame">Overview</a></td><td><a href="http://www.erlang.org/"><img src="erlang.png" align="right" border="0" alt="erlang logo"></a></td></tr></table></div> <p><i>Generated by EDoc, Mar 9 2013, 09:38:58.</i></p> </body> </html>