<html><head><style type="text/css">body { background: rgba(255, 255, 255, 255); }</style></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: #1501d7"><b>nopoll_bool</b></span> onConnReady (<span style="color: #1501d7"><b>noPollCtx</b></span>* wsctx, <span style="color: #1501d7"><b>noPollConn</b></span>* conn, <span style="color: #1501d7"><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: #1501d7"><b><span class="Apple-tab-span" style="white-space:pre"> </span>noPollConn</b></span>* listener = (<span style="color: #1501d7"><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: #000000">(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: 11.0px Menlo; color: #000000"><span class="Apple-tab-span" style="white-space:pre"> </span></span><b>return</b><span style="font: 11.0px Menlo; color: #000000"> </span><b>true</b><span style="font: 11.0px Menlo; color: #000000">;</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: #1501d7"><b>noPollConn</b></span>* listener = <span style="color: #8134d7"><i>nopoll_listener_new</i></span>(wsctx, <span style="font: 11.0px Monaco; color: #ff0000">"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: #8134d7"><i>nopoll_ctx_set_on_ready</i></span>(wsctx, &<span style="color: #94676a"><i>onConnReady</i></span>, (<span style="color: #1501d7"><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 and Happy new year !</div><div><br></div><div><div>
<div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><hr><pre>Félix Faisant</pre></div></div>
</div>
<br></div></body></html>