<div dir="auto"><div>Oh, my apologies! I was thinking about listen and connect - serves me right for replying before having a coffee :) In that case I don't really have a good answer for your question. <br><div class="gmail_extra"><br><div class="gmail_quote">On 6 Feb 2018 08:29, "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">But listen and accept are both on the server side. Does that have anything to do w/ the client?<div><br></div><div>I'll have to read up more on the TCP protocol before investigating this further, I guess.<div class="elided-text"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Feb 6, 2018 at 12:26 AM, Karl Velicka <span dir="ltr"><<a href="mailto:karolis.velicka@gmail.com" target="_blank">karolis.velicka@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div>The case where you are in control of both the server and the client is not so common outside of book examples, so you'd be only configuring your end of the connection. And even when you control both, there can be many reasons for configuring your sockets differently. <div><div class="m_-2101363265307827384h5"><br><div class="gmail_extra"><br><div class="gmail_quote">On 6 Feb 2018 08:20, "Tianxiang Xiong" <<a href="mailto:tianxiang.xiong@gmail.com" target="_blank">tianxiang.xiong@gmail.com</a>> wrote:<br type="attribution"><blockquote class="m_-2101363265307827384m_8723254135357595304quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">OK, so the same options need to be set for listen / accept? That seems kind of redundant--is there a reason for that? Or are these usually different options?<div class="m_-2101363265307827384m_8723254135357595304elided-text"><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Feb 6, 2018 at 12:14 AM, Karl Velicka <span dir="ltr"><<a href="mailto:karolis.velicka@gmail.com" target="_blank">karolis.velicka@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><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"><div><div class="m_-2101363265307827384m_8723254135357595304m_5368886021015808059h5">On 6 Feb 2018 07:55, "Tianxiang Xiong" <<a href="mailto:tianxiang.xiong@gmail.com" target="_blank">tianxiang.xiong@gmail.com</a>> wrote:<br type="attribution"></div></div><blockquote class="m_-2101363265307827384m_8723254135357595304m_5368886021015808059m_-6143869804686685380quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="m_-2101363265307827384m_8723254135357595304m_5368886021015808059h5"><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,tr<wbr>ue},{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></div></div>______________________________<wbr>_________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank">http://erlang.org/mailman/list<wbr>info/erlang-questions</a><br>
<br></blockquote></div><br></div></div></div>
</blockquote></div><br></div></div></div>
</blockquote></div><br></div></div></div></div></div>
</blockquote></div><br></div></div></div></div>
</blockquote></div><br></div></div></div>