From 72b1e75d9bfc7340c3e4a7158cf1c21ae467d52a Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Fri, 8 Feb 2019 15:17:56 +0100 Subject: [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 --- erts/doc/src/socket.xml | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) (limited to 'erts/doc') 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 @@ Socket interface.

This module provides an API for the socket interface. - It is used to create, delete and manipulate sockets.

+ It is used to create, delete and manipulate sockets, + send and receive data.

+

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. recv/3, + has a timeout argument.

@@ -574,7 +580,34 @@
Examples -

TBD

+ +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). +
-- cgit v1.2.3