Note that there are some explanatory texts on larger screens.

plurals
  1. POSocket server cannot accept data after set active mode 'once'
    primarykey
    data
    text
    <p>I'm a erlang newbie. When I read the Socket chapter from "Programming Erlang" and doing some examples according to the tutorial, there is a problem.</p> <p>In the chapter "The Hybrid Approach (Partial Blocking)", I do the following:</p> <pre><code>loop(Socket)-&gt; receive {tcp, Socket, Bin} -&gt; io:format("Server received binary = ~p~n",[Bin]), Str = binary_to_term(Bin), io:format("Server (unpacked) ~p~n",[Str]), Reply = lib_misc:string2value(Str), io:format("Server replying = ~p~n",[Reply]), gen_tcp:send(Socket, term_to_binary(Reply)), inet:setopts(Socket,[binary,{active, once}]), %Configure socket as active loop(Socket); {tcp_closed, Socket} -&gt; io:format("Server socket closed~n") end. start()-&gt; {ok,Listen} = gen_tcp:listen(2345,[binary,{packet,4}, {reuseaddr, true}, {active, once}]), {ok, Socket} = gen_tcp:accept(Listen), loop(Socket). sendData(Str)-&gt; {ok,Socket}=gen_tcp:connect("localhost",2345,[binary,{packet,4}]), ok=gen_tcp:send(Socket, term_to_binary(Str)), receive {tcp,Socket,Bin}-&gt; io:format("Client received binary = ~p~n",[Bin]), Val = binary_to_term(Bin), io:format("Client result=~p~n",[Val]) % gen_tcp:close(Socket) end. </code></pre> <p>Then I open one terminal like this: $erl</p> <blockquote> <p>server:start().</p> </blockquote> <p>and open another terminal like this: $erl</p> <blockquote> <p>client:sendData("1233").</p> </blockquote> <p>At server, it will output: Server received binary = &lt;&lt;131,107,0,3,49,50,51>> Server (unpacked) "123" Server replying = 123</p> <p>At client, it will output: Client received binary = &lt;&lt;131,97,123>> Client result=123</p> <p>But when the client sendData second time, there is not any response at server. Is there something wrong? Thank you.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload