Chris's Wiki :: blog/python/SocketModuleIrritations Commentshttps://utcc.utoronto.ca/~cks/space/blog/python/SocketModuleIrritations?atomcommentsDWiki2006-05-20T21:18:03ZRecent comments in Chris's Wiki :: blog/python/SocketModuleIrritations.By Chris Siebenmann on /blog/python/SocketModuleIrritationstag:CSpace:blog/python/SocketModuleIrritations:67301e248e6aa4012c2292e906c1077195d7151aChris Siebenmann<div class="wikitext"><p>Oops, it looks like I missed reading IO:Socket::INET carefully when I last
wrote a Perl network program; in hindsight it provides all of the stuff
that I want, and at the same high level that Python provides.</p>
<p>Is IO::Socket a standard part of the Perl distribution? If it is, maybe
it's time for the perlfunc manpage to cover it when discussing the
low-level socket stuff.</p>
</div>2006-05-20T21:18:03ZBy Chris Siebenmann on /blog/python/SocketModuleIrritationstag:CSpace:blog/python/SocketModuleIrritations:5f6c60849fb2df681a83855373b3df2101310996Chris Siebenmann<div class="wikitext"><p><code>openssl s_client</code> isn't useful for scripting, because it prints too
much goop (even with <code>-quiet</code>, and <code>-quiet</code> turns off handling of input
EOF). And even though I could use it for command line usage all of the
goop annoys the heck out of me in the majority of the cases when it's
not interesting.</p>
<p>In testing I see that openssl also kills the entire connection on input
EOF, which is not at all what you want in a netcat-like program; it should
shut down the sending end, but keep receiving until network EOF.</p>
</div>2006-05-20T21:06:30ZFrom 129.241.93.32 on /blog/python/SocketModuleIrritationstag:CSpace:blog/python/SocketModuleIrritations:cc17f78e64d2816e5c57fc4266e22e81537a2f6fFrom 129.241.93.32<div class="wikitext"><p>Why would you want to write a separate Python program for SSL-aware netcat? "openssl s_client" works just fine...</p>
<p>- Steinar H. Gunderson (sgunderson@bigfoot.com, just in case)</p>
</div>2006-05-20T12:36:37ZBy DanielMartin on /blog/python/SocketModuleIrritationstag:CSpace:blog/python/SocketModuleIrritations:59ebf8a67554936d809ce147a0a829ca051a6757DanielMartin<div class="wikitext"><blockquote><p>(And somewhat easier than doing so in Perl, because Perl forces a somewhat lower level view of the whole mess.)</p>
</blockquote>
<p>"Forces" is a bit strong, since perl has included the IO::Socket module as part of the base perl distribution since version 5.004 (May 1997). With that module, you can do stuff like this:</p>
<pre>
#!/usr/bin/perl -w
use IO::Socket;
use strict;
my $remote = IO::Socket::INET->new(
Proto => "tcp",
PeerAddr => "localhost",
PeerPort => "daytime(13)",
)
or die "cannot connect to daytime port at localhost";
while ( <$remote> ) { print }
</pre>
<p>This seems pretty straightforward to me. If that's too verbose you can call the constructor as</p>
<pre>
my $remote = IO::Socket::INET->new( "localhost:13" )
</pre>
<p>True, you can use the low-level socket stuff directly if you want, and a regrettable amount of example code will recommend that instead of IO::Socket, but that's hardly on the same level as the language forcing you to use the low-level interface.</p>
</div>2006-05-20T12:27:43Z