<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>chrisjrn&#039;s site &#187; sockets</title>
	<atom:link href="http://chris.neugebauer.id.au/tags/sockets/feed/" rel="self" type="application/rss+xml" />
	<link>http://chris.neugebauer.id.au</link>
	<description>Indeed it is.</description>
	<lastBuildDate>Tue, 24 Jan 2012 23:06:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>Fun with Sockets</title>
		<link>http://chris.neugebauer.id.au/2008/10/28/fun-with-sockets/</link>
		<comments>http://chris.neugebauer.id.au/2008/10/28/fun-with-sockets/#comments</comments>
		<pubDate>Tue, 28 Oct 2008 10:06:00 +0000</pubDate>
		<dc:creator>Christopher Neugebauer</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[sockets]]></category>

		<guid isPermaLink="false">http://chris.neugebauer.id.au/2008/10/28/fun-with-sockets/</guid>
		<description><![CDATA[Whilst doing some coding today for my semester research project I found a need to check for incoming data on a socket without taking any data out of the stream. Here&#8217;s the code I came up with: cp.sock.setblocking(False) try: cp.sock.recv(0) &#8230; <a href="http://chris.neugebauer.id.au/2008/10/28/fun-with-sockets/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Whilst doing some coding today for my semester research project I found a need to check for incoming data on a socket without taking any data out of the stream.  Here&#8217;s the code I came up with:</p>
<pre> cp.sock.setblocking(False) try: cp.sock.recv(0) stuffwaiting = True except socket.error: stuffwaiting = False cp.sock.setblocking(True) </pre>
<p>This code works finely on Linux &#8212; you can only receive data if there is data to be received (even if you want to receive no data).  Unfortunately, the code doesn&#8217;t port to Mac OS &#8212; you may receive as many bytes as there are in the socket&#8217;s buffer &#8212; if there are no bytes in the buffer, you can receive 0 bytes.  Therefore, the following fix is necessary:</p>
<pre> cp.sock.setblocking(False) try: cp.sock.recv(1, socket.MSG_PEEK) stuffwaiting = True except socket.error: stuffwaiting = False cp.sock.setblocking(True) </pre>
<p>So, my question for Lazyweb is: is there a better way to do this?</p>
]]></content:encoded>
			<wfw:commentRss>http://chris.neugebauer.id.au/2008/10/28/fun-with-sockets/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

