<?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>cloud goes social &#187; python</title>
	<atom:link href="http://www.cloudgoessocial.net/tag/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.cloudgoessocial.net</link>
	<description>computer, travel, movies, music, cuisine and more</description>
	<lastBuildDate>Thu, 09 Sep 2010 07:46:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>TIME protocol on MacOSX</title>
		<link>http://www.cloudgoessocial.net/2009/04/15/time-protocol-on-macosx/</link>
		<comments>http://www.cloudgoessocial.net/2009/04/15/time-protocol-on-macosx/#comments</comments>
		<pubDate>Wed, 15 Apr 2009 20:44:55 +0000</pubDate>
		<dc:creator>Cloud</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[macosx]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.cloudgoessocial.net/?p=11</guid>
		<description><![CDATA[Recently in the Advanced Operating System course, at ETH (Systems) I&#8217;ve struggled upon the TIME protocol (not NTP). The problem was simple: get a TIME protocol server that could respond to the SLUG2 (friendly called by me and my project partner SLUT) when &#8216;she&#8217; was needing a reply (for some randomness, apparently). Since MacOSX doesn&#8217;t]]></description>
			<content:encoded><![CDATA[<p>Recently in the Advanced Operating System course, at <a href="http://www.systems.ethz.ch">ETH (Systems)</a> I&#8217;ve struggled upon the <a href="http://en.wikipedia.org/wiki/TIME_protocol">TIME protocol</a> (not NTP). The problem was simple: get a TIME protocol server that could respond to the SLUG2 (friendly called by me and my project partner SLUT) when &#8216;she&#8217; was needing a reply (for some randomness, apparently).</p>
<p>Since MacOSX doesn&#8217;t provide any such thing, I settled on the task and here&#8217;s the result:</p>
<p>Server side:</p>
<pre class="brush: python;">
#!/usr/bin/env python

import time
from socket import *

def server(host=&quot;&quot;, port=37):
	sock = socket (AF_INET, SOCK_DGRAM)
	sock.bind ((host, port))

	print &quot;listening on port %s (%s)&quot; % (port, `host`)
	while 1:
		# Block waiting for packet.
		data, address = sock.recvfrom(256)
		print &quot;Client sent:&quot;, data
		print &quot;Client at:&quot;, address
		# Got a packet, reply to address packet came from.
		sock.sendto(time.time(),address)

if __name__ == &quot;__main__&quot;:
	server(&quot;&quot;, 37)
</pre>
<p>Client side (just to test that the server is actually working)</p>
<pre class="brush: python;">
#!/usr/bin/env python

import socket
port=37
clisocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
while 1:
	data = raw_input(&quot;Type something: &quot;)
	if data:
		clisocket.sendto(data, (&quot;127.0.0.1&quot;, port))
		# Block waiting for reply.
		data, address = clisocket.recvfrom(256)
		print &quot;Server sent time:&quot;, data
	else:
		break

clisocket.close()
</pre>
<p>This code (and any other that might be present on this blog) should be taken with a good grain of salt. It seems to do what it&#8217;s supposed to do. So if you&#8217;re in an emergency, trying to find a TIME protocol server to make it answer your client needs, here it is. Fiddle with it as much as you want. And don&#8217;t hesitate to comment with good and bad news about it.</p>
<p>The code and the issue have been tested on MacOSX 10.5.6</p>
<p>ciop ciop</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cloudgoessocial.net/2009/04/15/time-protocol-on-macosx/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
