I am implementing simple TCP server with the following sequence:
{ok , LS} = Gen_tcp: listen (port, [{active, true}, {reusider, true}, {mode, list}}, {ok, socket} = gn_tcp: approved (ls), pd = spawn_link (m, Using the option How?
Div class = "post-text" itemprop = "text">
You are right In such cases you are certain You must pass between the {active, incorrect} socket options. Consider this snippet of code: - define (TCP_OPTIONS, [binary, {active, wrong}, ...]). ... Start (Port) - & gt; {OK, SOCKET} = GNTTP: listen (port, "TCPOOPTNS"), accept (socket) Accept (Sunsets) - & gt; Case gen_tcp: {ok, Socket} - & gt; Accept (sunsocket) Pid = spawn (funny) - & gt; Io: Format ("Connection Accepted ~ N", []), enter_loop (Socket End), gen_tcp: controlling_process (Socket, PID), PID! ACC, Accept (Sunsocket); Error - & gt; Exit (error) End Enter_loop (sock) - & gt; In order to accept the transmission rights of %% owner, make sure that ACC - & gt; Ok, loop (soak) loop (sock) - & gt; %% set soscket option to get messages in its own right: setopts (Sock, [{active, once]]], {TCP, socket, data} - & gt; get receive. Io: Format ("Packet Received: ~ P ~ N", [Data]), ..., Loop (Socket); {TCP_closed, socket} - & gt; Io: format ("socket ~ p off ~ n", [socket]); {Tcp_error, Socket, Reason} - & gt; Io: format ("socket ~ p cause error: ~ p ~ n", [socket, reason]) end. In this way you will not lose anything until the "code" controlling_process is successful. It is known that there have been a lot of discussions on the Internet on the problems. If you want to use the solution ready, you definitely have to take a look at the project.
Comments
Post a Comment