Python TimeServer (RFC 868)

Jeff jam at quark.emich.edu
Thu Sep 30 00:15:47 EDT 1999


On Thu, Sep 30, 1999 at 01:57:13AM +0000, Benjamin Schollnick wrote:
> Jeff,
>  
[..snipped..]
> 
> 		- Benjamin

greetings.

I poked around a little, and came up with some code, which I have attached.
please let me know if it works for you-- I haven't tested it other than to
telnet to the port, and it seems to work.. I've got no idea if it will work
under NT or not (though I can't think of any particular reason why it
wouldn't), but use it for what it's worth.

-- begin code --
#!/usr/bin/env python

import socket
import struct

def timeserver_calculation():
	import time
	
	return time.time()

def server(host="", port=3737, backlog=5):
	sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
	sock.bind(host, port)
	sock.listen(backlog)
	print "listening on port %s (%s, %d)" % (port, host, backlog)
	while 1:
		conn, addr = sock.accept()
		print "connected by %s at %s" % (conn, addr)
		ft = timeserver_calculation()
		conn.send(struct.pack("!i", ft))
		conn.close()

if __name__ == "__main__":
	server("localhost", 3737)
-- end code --

-- 
|| visit gfd <http://quark.newimage.com/> 
|| psa member #293 <http://www.python.org/> 
|| New Image Systems & Services, Inc. <http://www.newimage.com/>




More information about the Python-list mailing list