aboutsummaryrefslogtreecommitdiffstats
path: root/erts/doc/src/socket.xml
diff options
context:
space:
mode:
authorMicael Karlberg <[email protected]>2019-02-08 15:17:56 +0100
committerMicael Karlberg <[email protected]>2019-02-22 19:45:52 +0100
commit72b1e75d9bfc7340c3e4a7158cf1c21ae467d52a (patch)
tree372ab2d3fd45addc4bb6426d2e3915c4522a43d0 /erts/doc/src/socket.xml
parent8aa6b2ca02b6f08fd66178209317fa5ac658a88a (diff)
downloadotp-72b1e75d9bfc7340c3e4a7158cf1c21ae467d52a.tar.gz
otp-72b1e75d9bfc7340c3e4a7158cf1c21ae467d52a.tar.bz2
otp-72b1e75d9bfc7340c3e4a7158cf1c21ae467d52a.zip
[socket|doc] Add a tiny bit more header text and an example
Add a bit more text in the (socket) module description. Also added a (very) basic example. OTP-14831
Diffstat (limited to 'erts/doc/src/socket.xml')
-rw-r--r--erts/doc/src/socket.xml37
1 files changed, 35 insertions, 2 deletions
diff --git a/erts/doc/src/socket.xml b/erts/doc/src/socket.xml
index ea2fde7dee..56737b1a8f 100644
--- a/erts/doc/src/socket.xml
+++ b/erts/doc/src/socket.xml
@@ -33,7 +33,13 @@
<modulesummary>Socket interface.</modulesummary>
<description>
<p>This module provides an API for the socket interface.
- It is used to create, delete and manipulate sockets.</p>
+ It is used to create, delete and manipulate sockets,
+ send and receive data.</p>
+ <p>The idea is that it shall be as "close as possible" to the OS
+ level socket interface. The only significant addition is that some of
+ the functions,
+ e.g. <seealso marker="#recv/3"><c>recv/3</c></seealso>,
+ has a timeout argument. </p>
</description>
<datatypes>
@@ -574,7 +580,34 @@
<section>
<title>Examples</title>
<marker id="examples"></marker>
- <p>TBD</p>
+ <code type="none">
+client(Addr, Port) ->
+ {ok, Sock} = socket:open(inet, stream, tcp),
+ ok = socket:bind(Sock, #{family => inet,
+ port => 0,
+ addr => any}),
+ ok = socket:connect(Sock, #{family => inet,
+ addr => Addr,
+ port => Port}),
+ Msg = list_to_binary("hello"),
+ ok = socket:send(Sock, Msg),
+ ok = socket:shutdown(Sock, write),
+ {ok, Msg} = socket:recv(Sock),
+ ok = socket:close(Sock).
+
+server(Addr, Port) ->
+ {ok, LSock} = socket:open(inet, stream, tcp),
+ ok = socket:bind(LSock, #{family => inet,
+ port => Port,
+ addr => Addr}),
+ ok = socket:listen(LSock),
+ {ok, Sock} = socket:accept(LSock),
+ {ok, Msg} = socket:recv(Sock),
+ ok = socket:send(Sock, Msg),
+ ok = socket:shutdown(Sock, write),
+ ok = socket:close(Sock),
+ ok = socket:close(LSock).
+ </code>
</section>
</erlref>