The SocketServer module

This module provides a framework for various kinds of socket-based servers. The module provides a number of classes that can be mixed and matched to create servers for different purposes.

The following example implements an Internet Time Protocol server, using this module. Use the timeclient script to try it out:

Example: Using the SocketServer module
# File:

import SocketServer
import time

# user-accessible port
PORT = 8037

# reference time
TIME1970 = 2208988800L

class TimeRequestHandler(SocketServer.StreamRequestHandler):
    def handle(self):
        print "connection from", self.client_address
        t = int(time.time()) + TIME1970
        b = chr(t>>24&255) + chr(t>>16&255) + chr(t>>8&255) + chr(t&255)

server = SocketServer.TCPServer(("", PORT), TimeRequestHandler)
print "listening on port", PORT

connection from ('', 1488)
connection from ('', 1489)

A Django site. rendered by a django application. hosted by webfaction.