<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hi,<div><br></div><div>I want to use a websocket server as a "one-time server".</div><div>More clearly : I set up a noPoll listener on a defined port and I wait for a client.</div><div>Once the client is connected, I want to close the listener to release the port and let other instances of my program to do the same thing.</div><div><br></div><div>For that I use this code :</div><div><br></div><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; "><span style="color: rgb(21, 1, 215); "><b>nopoll_bool</b></span> onConnReady (<span style="color: rgb(21, 1, 215); "><b>noPollCtx</b></span>* wsctx, <span style="color: rgb(21, 1, 215); "><b>noPollConn</b></span>* conn, <span style="color: rgb(21, 1, 215); "><b>noPollPtr</b></span> data) {</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; "><span class="Apple-tab-span" style="white-space: pre; ">     </span>...</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; "><span style="color: rgb(21, 1, 215); "><b><span class="Apple-tab-span" style="white-space: pre; ">    </span>noPollConn</b></span>* listener = (<span style="color: rgb(21, 1, 215); "><b>noPollConn</b></span>*)data;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(129, 52, 215); "><i><span class="Apple-tab-span" style="white-space: pre; ">     </span>nopoll_conn_close</i><span style="color: rgb(0, 0, 0); ">(listener);</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; "><span class="Apple-tab-span" style="white-space: pre; ">        </span>...</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Menlo; color: rgb(33, 0, 175); "><span style="font: normal normal normal 11px/normal Menlo; color: rgb(0, 0, 0); "><span class="Apple-tab-span" style="white-space: pre; ">  </span></span><b>return</b><span style="font: normal normal normal 11px/normal Menlo; color: rgb(0, 0, 0); "> </span><b>true</b><span style="font: normal normal normal 11px/normal Menlo; color: rgb(0, 0, 0); ">;</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; ">}</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; ">...</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; "><span style="color: rgb(21, 1, 215); "><b>noPollConn</b></span>* listener = <span style="color: rgb(129, 52, 215); "><i>nopoll_listener_new</i></span>(wsctx, <span style="font: normal normal normal 11px/normal Monaco; color: rgb(255, 0, 0); ">"0.0.0.0"</span>, port);</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; ">...</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; "><span style="color: rgb(129, 52, 215); "><i>nopoll_ctx_set_on_ready</i></span>(wsctx, &<span style="color: rgb(148, 103, 106); "><i>onConnReady</i></span>, (<span style="color: rgb(21, 1, 215); "><b>noPollPtr</b></span>)listener);</div></div><div><br></div><div>But when the connection is established, even after '<span class="Apple-style-span" style="color: rgb(129, 52, 215); font-family: Menlo; font-size: 11px; "><i>nopoll_conn_close</i></span><span class="Apple-style-span" style="color: rgb(129, 52, 215); font-family: Menlo; font-size: 11px; "><span style="color: rgb(0, 0, 0); ">(listener)</span></span>', the listening port is still used by the process :</div><div><br></div><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Monaco; "># lsof -i</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Monaco; ">COMMAND    PID   ...  NODE NAME</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Monaco; ">my_program 3428  ...  TCP  *:29800 (LISTEN)</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Monaco; ">my_program 3428  ...  TCP  [me]:29800->[client]:58908 (ESTABLISHED)</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal Monaco; ">my_program 3428  ...  TCP  [me]:57345->[client]:29254 (ESTABLISHED)</div></div><div><br></div><div>Does the listener can release the port, or do I need to rethink everything ?</div><div>I didn't try creating my own listener. Maybe I should ?</div><div><br></div><div>Thanks in advance !</div><div><br></div><div>
<span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: 'Lucida Grande'; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: 'Lucida Grande'; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: 'Lucida Grande'; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><hr></div></div></span></div></span><pre>Félix Faisant - <span class="Apple-style-span" style="font-family: 'Lucida Grande'; white-space: normal; "><a href="http://www.xif.fr/">xif.fr</a></span></pre></span>
</div>
<br></body></html>