diff --git a/assignments/week01/lab/echo_client.py b/assignments/week01/lab/echo_client.py index b8898436..023bfba0 100644 --- a/assignments/week01/lab/echo_client.py +++ b/assignments/week01/lab/echo_client.py @@ -1,16 +1,34 @@ import socket import sys +# Create a function for requesting numbers from the users +def get_num(): + """ This function takes two numbers 'x' and 'y' and returns a string """ + list_num = raw_input(' Please enter two comma seperated numbers > ') + return list_num + # Create a TCP/IP socket +echo_client = socket.socket(socket.AF_INET,socket.SOCK_STREAM) # Connect the socket to the port where the server is listening server_address = ('localhost', 50000) +echo_client.connect(server_address) try: + # Send data - message = 'This is the message. It will be repeated.' + message = get_num() + print >>sys.stderr, 'sending "%s"' % message + echo_client.sendall(message) + + # receive the response from the server + data = echo_client.recv(1024) # print the response + print >>sys.stderr, 'Computed sum of %s is "%s"' % (message, data) finally: # close the socket to clean up + print >>sys.stderr, 'closing socket' + echo_client.close() + diff --git a/assignments/week01/lab/echo_server.py b/assignments/week01/lab/echo_server.py index e2c52fc6..bdf449d4 100644 --- a/assignments/week01/lab/echo_server.py +++ b/assignments/week01/lab/echo_server.py @@ -1,19 +1,45 @@ import socket import sys +# Create a function to sum the numbers from the users +def num_sum(msg): + """ This function resturns the sum of a list of integers """ + num_sum = 0 + for i in range(len(msg)): + num_sum += int(msg[i]) + return num_sum + # Create a TCP/IP socket +echo_server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # Bind the socket to the port server_address = ('localhost', 50000) +print >>sys.stderr, 'starting up on %s port %s' % server_address +echo_server.bind(server_address) # Listen for incoming connections +echo_server.listen(1) while True: # Wait for a connection - + print >>sys.stderr, 'waiting for a connection' + connection, client_address = echo_server.accept() try: - # Receive the data and send it back + print >>sys.stderr, 'connection from', client_address + + # Receive the data + message = connection.recv(1024) + data = message.split(',') + print >>sys.stderr, 'received "%s"' % data + + # Compute the sum + return_data = str(num_sum(data)) + + # Send the data back to the client + print >>sys.stderr, 'sending return_data back to the client', return_data + connection.sendall(return_data) finally: # Clean up the connection + connection.close() diff --git a/assignments/week04-readme.txt b/assignments/week04-readme.txt new file mode 100644 index 00000000..1068d743 --- /dev/null +++ b/assignments/week04-readme.txt @@ -0,0 +1,21 @@ +README + +1. Select the following link - runs book1_cgi.py +http://block647062-yym.blueboxgrid.com/cgi-bin/book1_cgi.py + +2. To display the database book index - runs book2_cgi.py +Click the hyper link INDEX OF THE BOOK DATABASE + +3. This will display an Index of books with their title +Click on the title and it will display the page + +4. Source Code is all contained in assignments/week04/athome/src +the following files comprise the code +bookdb.py +book1_cgi.py +book2_cgi.py +book2_wsgi_id1.py +book2_wsgi_id2.py +book2_wsgi_id3.py +book2_wsgi_id4.py +book2_wsgi_id5.py