<div dir="auto"><div>Hi, </div><div dir="auto"><br></div><div dir="auto">You don't have to set the options separately for accept, there's a two argument version that takes a proplist of socket options. </div><div dir="auto"><br></div><div dir="auto">When you're using gen_tcp:listen then you're setting up a server that receives connections, whereas `accept` is connecting to something that's listening to connections. You need to set the socket options separately in each case.</div><div dir="auto"><br></div><div dir="auto">Hope that helps! <br><div class="gmail_extra" dir="auto"><br><div class="gmail_quote">On 6 Feb 2018 07:55, "Tianxiang Xiong" <<a href="mailto:tianxiang.xiong@gmail.com">tianxiang.xiong@gmail.com</a>> wrote:<br type="attribution"><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">In Joe's <a href="https://pragprog.com/book/jaerlang2/programming-erlang" target="_blank">Programming Erlang 2nd E</a>, Chpt. 17, pg. 274, he says:<div><br><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">After we have accepted a connection, it’s a good idea to explicitly set the required socket options, like this:</blockquote><div><div><br></div><div><font face="monospace, monospace">{ok, Socket} = gen_tcp:accept(Listen),</font></div><div><font face="monospace, monospace">inet:setopts(Socket, [{packet,4},binary,</font><span style="font-family:monospace,monospace">{nodelay,<wbr>true},{active, true}]),</span></div><div><font face="monospace, monospace">loop(Socket)</font></div></div></div></div><div><br></div><div>Until then the book's been doing:</div><div><br></div><div><font face="monospace, monospace">{ok, Listen} = gen_tcp:listen(2345, [binary, {packet, 4}, {reuseaddr, true}, {active, true}])<br></font></div><div><font face="monospace, monospace">{ok, Socket} = gen_tcp:accept(Listen),<br></font></div><div><font face="monospace, monospace">...</font></div><div><font face="monospace, monospace">loop(Socket)</font></div><div><br></div><div>Is there a reason we need to set the options after accept? Is it necessary to set options on listen <i>and</i> accept?</div><div><br></div></div>
<br>______________________________<wbr>_________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank">http://erlang.org/mailman/<wbr>listinfo/erlang-questions</a><br>
<br></blockquote></div><br></div></div></div>