<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Aptos;
panose-1:2 11 0 4 2 2 2 2 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
font-size:12.0pt;
font-family:"Aptos",sans-serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
span.EmailStyle18
{mso-style-type:personal-reply;
font-family:"Aptos",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;
mso-ligatures:none;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style>
</head>
<body lang="EN-US" link="blue" vlink="purple" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt">For what it’s worth, the way I looked at his code was that the “listenOn: port” should have thrown an RTE as the OS knows immediately that the port is not available. Of course Mark’s code below doesn’t handle
errors there, but that would have been resolved during debugging. Whether or not the rest of the code is sane is another matter entirely
</span><span style="font-size:11.0pt;font-family:"Apple Color Emoji"">😊</span><span style="font-size:11.0pt">.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">Jon<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<div id="mail-editor-reference-message-container">
<div>
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal" style="margin-bottom:12.0pt"><b><span style="color:black">From:
</span></b><span style="color:black">Cuis-dev <cuis-dev-bounces@lists.cuis.st> on behalf of Gerald Klix via Cuis-dev <cuis-dev@lists.cuis.st><br>
<b>Date: </b>Thursday, October 24, 2024 at 12:25</span><span style="font-family:"Arial",sans-serif;color:black"> </span><span style="color:black">PM<br>
<b>To: </b>cuis-dev@lists.cuis.st <cuis-dev@lists.cuis.st><br>
<b>Cc: </b>Gerald Klix <cuis.01@klix.ch><br>
<b>Subject: </b>Re: [Cuis-dev] finding an open port<o:p></o:p></span></p>
</div>
<p class="MsoNormal">Dear Mark,<br>
<br>
why in name of Alan (Perlis) do you expect a connection to your newly<br>
created server socket pop out of nowhere?<br>
<br>
Increase the time out to 60 in `connected := socket <br>
waitForConnectionFor: 1 ifTimedOut: [ false ].`,<br>
send the #openPortFrom: message to your object.<br>
<br>
Switch to Terminal window, and start telnet like this<br>
`telnet <a href="http://127.0.0.1">
127.0.0.1</a> 3000` and marvel at the results.<br>
<br>
Sorry for my harsh words: This issue has nothing to do with Cuis,<br>
but a lot with socket, bind and listen.<br>
<br>
See man 2 bind, man 2 listen<br>
<br>
<br>
Just my 0,01€,<br>
<br>
Gerald<br>
<br>
<br>
<br>
On 10/24/24 2:29 AM, Mark Volkmann via Cuis-dev wrote:<br>
> I wrote the following code to take a port number and return the first port<br>
> starting from that number that is open. For example, if ports 3000 and 3001<br>
> are in use and I send "MyClass openPortFrom: 3000" then I expect it to<br>
> return 3002. Can you spot why this never finds an open port and loops<br>
> forever?<br>
><br>
> openPortFrom: aNumber<br>
> | connected port socket |<br>
><br>
> connected := false.<br>
> port := aNumber.<br>
><br>
> [ connected ] whileFalse: [<br>
> 'trying port {1}' format: { port } :: print.<br>
> socket := Socket newTCP.<br>
> socket listenOn: port.<br>
> connected := socket waitForConnectionFor: 1 ifTimedOut: [ false ].<br>
> connected ifTrue: [socket disconnect] ifFalse: [ port := port + 1 ].<br>
> ].<br>
><br>
> ^port.<br>
><br>
><br>
<br>
-- <br>
Cuis-dev mailing list<br>
Cuis-dev@lists.cuis.st<br>
<a href="https://lists.cuis.st/mailman/listinfo/cuis-dev">https://lists.cuis.st/mailman/listinfo/cuis-dev</a><o:p></o:p></p>
</div>
</div>
</div>
</div>
</body>
</html>