#!/Library/Frameworks/Python.framework/Versions/Current/bin/python # L-29 MCS 275 Fri 19 Mar 2010 : scripts_showall.py # This script performs the action invoked by scripts_sort.py. # It is known as the "submit client" by the database server # scripts_sortdb.py. import cgi from socket import * hostname = 'localhost' # on same host number = 11267 # same port number buffer = 80 # size of the buffer def PrintHeader(title): """ writes title and header of page """ print """Content-type: text/html %s """ % title def SendSortOrder(cs): """ Sends sort order to server using the client socket cs. """ form = cgi.FieldStorage() sortby = form['sort'].value if eval(form['order'].value): sortby = sortby + '+' else: sortby = sortby + '-' cs.send(sortby) def RetrieveTable(cs,n): """ Retrieves table of n records, using socket cs to communicate. """ print "" for i in range(0,n): data = cs.recv(buffer) d = data.split(':') print "" print "" % i print "" % d[0] print "" % d[1] print "" % d[2] print "" print "
%d%s%s%s
" def main(): """ Connects and prints data of server. """ PrintHeader('showing all scripts') server_address = (hostname, number) client = socket(AF_INET, SOCK_STREAM) client.connect(server_address) data = client.recv(buffer) n = int(data) print "Number of scripts : %d" % n SendSortOrder(client) RetrieveTable(client,n) client.close() main()