<div dir="ltr">Well i don't want to be nit picking however, i believe you're mistaken here.  You can reuse port on which you are listening for outgoing connections too.<div>You need to use<i><b> setsockopt(... SO_REUSEPORT ).</b></i>..  </div><div>here goes the demo: </div><div><br></div><div><pre style="background-color:rgb(255,255,255);color:rgb(0,0,0);font-family:"DejaVu Sans Mono";font-size:11.3pt"><span style="color:rgb(128,128,128);font-style:italic">#!/usr/bin/python3<br></span><span style="color:rgb(0,0,128);font-weight:bold">import </span>socket<br><span style="color:rgb(0,0,128);font-weight:bold">import </span>threading<br><br><br>READER1_ADDR = (<span style="color:rgb(0,128,128);font-weight:bold">"127.0.0.1"</span>, <span style="color:rgb(0,0,255)">23008</span>)<br>READER2_ADDR = (<span style="color:rgb(0,128,128);font-weight:bold">"127.0.0.1"</span>, <span style="color:rgb(0,0,255)">23009</span>)<br><br><br><br><span style="color:rgb(0,0,128);font-weight:bold">class </span>wait_conn(threading.Thread):<br>    <span style="color:rgb(0,0,128);font-weight:bold">def </span><span style="color:rgb(178,0,178)">__init__</span>(<span style="color:rgb(148,85,141)">self</span>, addr, name):<br><br>        <span style="color:rgb(0,0,128)">super</span>(wait_conn,<span style="color:rgb(148,85,141)">self</span>).<span style="color:rgb(178,0,178)">__init__</span>()<br><br>        <span style="color:rgb(148,85,141)">self</span>.name = name<br>        <span style="color:rgb(148,85,141)">self</span>.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM, <span style="color:rgb(0,0,255)">0</span>)<br>        <span style="color:rgb(148,85,141)">self</span>.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, <span style="color:rgb(0,0,255)">1</span>)<br>        <span style="color:rgb(148,85,141)">self</span>.sock.bind(addr)<br>        <span style="color:rgb(148,85,141)">self</span>.sock.listen(<span style="color:rgb(0,0,255)">3</span>)<br><br>    <span style="color:rgb(0,0,128);font-weight:bold">def </span>run(<span style="color:rgb(148,85,141)">self</span>):<br>        s, a = <span style="color:rgb(148,85,141)">self</span>.sock.accept()<br>        <span style="color:rgb(0,0,128)">print</span>(<span style="color:rgb(148,85,141)">self</span>.name, <span style="color:rgb(0,128,128);font-weight:bold">": Incomming connection from: "</span>,  s.getpeername())<br>        s.close()<br>        <span style="color:rgb(148,85,141)">self</span>.sock.close()<br><br><br>t1 = wait_conn(READER1_ADDR, <span style="color:rgb(0,128,128);font-weight:bold">"r1"</span>)<br>t1.start()<br>t2 = wait_conn(READER2_ADDR, <span style="color:rgb(0,128,128);font-weight:bold">"r2"</span>)<br>t2.start()<br><br>w1 = socket.socket(socket.AF_INET, socket.SOCK_STREAM, <span style="color:rgb(0,0,255)">0</span>)<br>w1.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, <span style="color:rgb(0,0,255)">1</span>)<br>w1.bind(READER1_ADDR)<br>w1.connect(READER2_ADDR)<br>w1.close()<br><br><br><br><br>t1.join(<span style="color:rgb(0,0,255)">1.0</span>)<br>t2.join(<span style="color:rgb(0,0,255)">1.0</span>)<br><br></pre><br></div><div><pre style="background-color:rgb(255,255,255);color:rgb(0,0,0);font-family:"DejaVu Sans Mono";font-size:11.3pt"><br></pre></div></div><div class="gmail_extra"><br><div class="gmail_quote">2018-06-21 21:27 GMT+02:00 Daniel-Constantin Mierla <span dir="ltr"><<a href="mailto:notifications@github.com" target="_blank">notifications@github.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p>Obviously the difference is that kamailio does bind() and listen() on the socket (ip:port) first -- maybe that should have said to be clear about what case we talk here. So try with socket(), bind(), listen() and then connect().</p>
<p>Once there is listen() on a socket, read events for it mean accept() should be done. The kernel won't create an outgoing connection from a listen socket, but use ephemeral ports.</p>

<p style="font-size:small;color:#666">—<br>You are receiving this because you commented.<span class=""><br>Reply to this email directly, <a href="https://github.com/kamailio/kamailio/issues/1532#issuecomment-399216138" target="_blank">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AF36ZceX6KXDz8U4aUKDqzbkS-kEvCLiks5t-_OKgaJpZM4UAV3q" target="_blank">mute the thread</a>.<img src="https://github.com/notifications/beacon/AF36ZT6R1QVOxPw23iKyhMiLjW7qbkDKks5t-_OKgaJpZM4UAV3q.gif" height="1" width="1" alt=""></span></p>


<br>______________________________<wbr>_________________<br>
Kamailio (SER) - Development Mailing List<br>
<a href="mailto:sr-dev@lists.kamailio.org">sr-dev@lists.kamailio.org</a><br>
<a href="https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-dev" rel="noreferrer" target="_blank">https://lists.kamailio.org/<wbr>cgi-bin/mailman/listinfo/sr-<wbr>dev</a><br>
<br></blockquote></div><br></div>