<div dir="ltr">The problem with connecting to 8.8.8.8 which is Google&#39;s public DNS server is that:<div>(a) you might not have access to the internet</div><div>(b) you might be going thru a proxy and it may not be on the school white-list</div><div>(c) tapping port 80 on the dns server likely won&#39;t work either. </div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Sep 21, 2015 at 11:17 AM, tim Rowledge <span dir="ltr">&lt;<a href="mailto:tim@rowledge.org" target="_blank">tim@rowledge.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><br>
<br>
On 21-09-2015, at 10:17 AM, tim Rowledge &lt;<a href="mailto:tim@rowledge.org">tim@rowledge.org</a>&gt; wrote:<br>
&gt; On 21-09-2015, at 5:27 AM, Bert Freudenberg &lt;<a href="mailto:bert@freudenbergs.de">bert@freudenbergs.de</a>&gt; wrote:<br>
</span><span class="">&gt;&gt; python -c &quot;import socket; s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM); s.connect((&#39;8.8.8.8&#39;, 80)); print(s.getsockname()[0]); s.close()&quot;<br>
&gt;&gt;<br>
&gt;&gt; I tried that on a Linux and OS X, works on both. We should be able to do that in Squeak using a UDP socket, no?<br>
<br>
</span>Doesn’t seem to want to work in my pi image; the simple version (bearing in mind an almost total lack of knowledge about sockets)<br>
<br>
| foo bar|<br>
foo := Socket newUDP.<br>
foo connectTo: #[8 8 8 8] port: 80.<br>
bar := foo localAddress.<br>
foo close.<br>
bar<br>
<br>
fails to do the connect since<br>
a) UDP sockets are created with the status set to connected<br>
b) the #connectNoBlockingTo:port: method carefully checks for the status and fails when it is not ‘Unconnected’.<br>
<br>
Trying a #setPeer:port: instead - which calls the primSocket:connectTo:port: directly and skips the status test - doesn’t leave me with anything interesting from #localAddress.<br>
<br>
I even tried a quick ‘sendUDPData:’hello’ toHost: #[8 8 8 8] port: 80’ (which appeared to work) and still localAddress is 0.0.0.0 ‘self peerName’ is <a href="http://google-public-dns-a.google.com" rel="noreferrer" target="_blank">google-public-dns-a.google.com</a> so it looks like I made some sort of connection.<br>
<br>
Substituting a newTCP for the newUDP actually returned a useful IP number after a long delay and a notifier that it couldn’t connect. So as a desperate last attempt I tried<br>
| foo bar|<br>
foo := Socket newTCP.<br>
foo setPeer: #[8 8 8 8] port: 80.<br>
bar := foo localAddress.<br>
foo close.<br>
bar<br>
- which worked essentially instantly. I even tried it on another Pi to make sure nothing was being locally cached.<br>
<br>
I guess I can live with that if it’s the best we can do but<br>
- does it point to a problem with our TCP sockets?<br>
- it can’t work (presumably) if the machine is not on an externally connected network, which is quite plausible in many schools in many countries<br>
- [8 8 8 8] is the sort of magic number nonsense I hate to see.<br>
<br>
Can’t we do better?<br>
<span class=""><br>
tim<br>
--<br>
tim Rowledge; <a href="mailto:tim@rowledge.org">tim@rowledge.org</a>; <a href="http://www.rowledge.org/tim" rel="noreferrer" target="_blank">http://www.rowledge.org/tim</a><br>
</span>Useful random insult:- Couldn&#39;t find his way through a maze even if the rats helped him.<br>
<br>
<br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr">===========================================================================<br>John M. McIntosh. Corporate Smalltalk Consulting Ltd <a href="https://www.linkedin.com/in/smalltalk" target="_blank">https://www.linkedin.com/in/smalltalk</a><br>===========================================================================<br></div></div></div></div>
</div>