diff --git a/.project b/.project
new file mode 100644
index 00000000..afb89d22
--- /dev/null
+++ b/.project
@@ -0,0 +1,17 @@
+
+
+ IPP
+
+
+
+
+
+ org.python.pydev.PyDevBuilder
+
+
+
+
+
+ org.python.pydev.pythonNature
+
+
diff --git a/.pydevproject b/.pydevproject
new file mode 100644
index 00000000..b7acad2c
--- /dev/null
+++ b/.pydevproject
@@ -0,0 +1,10 @@
+
+
+
+
+
+/IPP
+
+python 2.7
+Default
+
diff --git a/assignments/week01/athome/addserver.py b/assignments/week01/athome/addserver.py
new file mode 100644
index 00000000..c5ba4eca
--- /dev/null
+++ b/assignments/week01/athome/addserver.py
@@ -0,0 +1,31 @@
+import socket
+import sys
+
+# Create a TCP/IP socket
+#aserver = socket.socket( 2, 1, 0) #Edit due to class example
+aserver = socket.socket(socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_IP)
+
+# Bind the socket to the port
+server_address = ('127.0.0.1', 50000)
+aserver.bind(server_address)
+# Listen for incoming connections
+aserver.listen(2) #listen(num) is the number of sequential connections allowed
+
+while True:
+# Wait for a connection
+ con, cli = aserver.accept()
+
+ try:
+ # Receive the data and send it back
+ msg = con.recv(1024)
+
+ a, b = (int(msg.split()[0]), int(msg.split()[1]))
+ thesum = str(a + b)
+ out = con.sendall(thesum)
+
+ finally:
+ # Clean up the connection
+ con.close()
+
+aserver.close()
+
\ No newline at end of file
diff --git a/assignments/week01/athome/client.py b/assignments/week01/athome/client.py
new file mode 100644
index 00000000..e4f4beb8
--- /dev/null
+++ b/assignments/week01/athome/client.py
@@ -0,0 +1,26 @@
+import socket
+import sys
+
+# Create a TCP/IP socket
+client = socket.socket(2,1,0)
+# Connect the socket to the port where the server is listening
+server_address = ('127.0.0.1', 50000)
+#server_address = ('208.85.148.104',50000)
+#server_address = ('block647050-tha.blueboxgrid.com',50000)
+
+client.connect(server_address)
+
+try:
+ # Send data
+ message = raw_input("Enter two numbers separated by a space: ")
+ #message = '2 5'
+ out = client.sendall(message)
+ response = client.recv(1024)
+ # print the response
+ print response
+
+finally:
+ # close the socket to clean up
+ client.close()
+
+
diff --git a/assignments/week01/lab/echo_client.py b/assignments/week01/lab/echo_client.py
index b8898436..96e063c8 100644
--- a/assignments/week01/lab/echo_client.py
+++ b/assignments/week01/lab/echo_client.py
@@ -2,15 +2,23 @@
import sys
# Create a TCP/IP socket
-
+client = socket.socket(2,1,0)
# Connect the socket to the port where the server is listening
-server_address = ('localhost', 50000)
+#server_address = ('127.0.0.1', 50000)
+server_address = ('208.85.148.104',50000)
+#server_address = ('block647050-tha.blueboxgrid.com',50000)
+client.connect(server_address)
try:
# Send data
- message = 'This is the message. It will be repeated.'
-
+ message = 'This is the message. It may be repeated.'
+ out = client.sendall(message)
+ response = client.recv(1024)
# print the response
-
+ print response
+
finally:
# close the socket to clean up
+ client.close()
+
+
diff --git a/assignments/week01/lab/echo_server.py b/assignments/week01/lab/echo_server.py
index e2c52fc6..22ab3ca0 100644
--- a/assignments/week01/lab/echo_server.py
+++ b/assignments/week01/lab/echo_server.py
@@ -2,18 +2,25 @@
import sys
# Create a TCP/IP socket
+aserver = socket.socket( 2, 1, 0)
# Bind the socket to the port
-server_address = ('localhost', 50000)
-
+server_address = ('127.0.0.1', 50000)
+aserver.bind(server_address)
# Listen for incoming connections
+aserver.listen(2) #listen(num) is the number of sequential connections allowed
while True:
- # Wait for a connection
-
+# Wait for a connection
+ con, cli = aserver.accept()
+
try:
# Receive the data and send it back
-
-
+ msg = con.recv(1024)
+ print msg
+ out = con.sendall('YES, received')
+
finally:
# Clean up the connection
+ con.close()
+
\ No newline at end of file
diff --git a/assignments/week02/lab/Sample_Scene_Balls.jpg b/assignments/week02/lab/Sample_Scene_Balls.jpg
new file mode 100644
index 00000000..1c0ccade
Binary files /dev/null and b/assignments/week02/lab/Sample_Scene_Balls.jpg differ
diff --git a/assignments/week02/lab/favicon.ico b/assignments/week02/lab/favicon.ico
new file mode 100644
index 00000000..c1b77883
Binary files /dev/null and b/assignments/week02/lab/favicon.ico differ
diff --git a/assignments/week02/lab/http_serve1.py b/assignments/week02/lab/http_serve1.py
new file mode 100644
index 00000000..1d16050c
--- /dev/null
+++ b/assignments/week02/lab/http_serve1.py
@@ -0,0 +1,38 @@
+#!/usr/bin/env python
+
+import socket
+import email
+
+host = '' # listen on all connections (WiFi, etc)
+port = 50000
+backlog = 5 # how many connections can we stack up
+size = 1024 # number of bytes to receive at once
+
+## create the socket
+s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+# set an option to tell the OS to re-use the socket
+s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
+
+# the bind makes it a server
+s.bind( (host,port) )
+s.listen(backlog)
+
+def ok_response(body):
+ return ( "HTTP/1.1 200 OK\r\n"
+ + "Content-Type: text/html\r\n"
+ + "Date: %s\r\n"%(email.Utils.formatdate())
+ + "\r\n"
+ + body )
+
+
+
+f = open('tiny_html.html')
+html = f.read()
+
+while True: # keep looking for new connections forever
+ client, address = s.accept() # look for a connection
+ data = client.recv(size)
+ if data: # if the connection was closed there would be no data
+ print "received: %s, sending back tiny_html"%data
+ client.send(ok_response(html))
+ client.close()
\ No newline at end of file
diff --git a/assignments/week02/lab/http_serve2.py b/assignments/week02/lab/http_serve2.py
new file mode 100644
index 00000000..1d16050c
--- /dev/null
+++ b/assignments/week02/lab/http_serve2.py
@@ -0,0 +1,38 @@
+#!/usr/bin/env python
+
+import socket
+import email
+
+host = '' # listen on all connections (WiFi, etc)
+port = 50000
+backlog = 5 # how many connections can we stack up
+size = 1024 # number of bytes to receive at once
+
+## create the socket
+s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+# set an option to tell the OS to re-use the socket
+s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
+
+# the bind makes it a server
+s.bind( (host,port) )
+s.listen(backlog)
+
+def ok_response(body):
+ return ( "HTTP/1.1 200 OK\r\n"
+ + "Content-Type: text/html\r\n"
+ + "Date: %s\r\n"%(email.Utils.formatdate())
+ + "\r\n"
+ + body )
+
+
+
+f = open('tiny_html.html')
+html = f.read()
+
+while True: # keep looking for new connections forever
+ client, address = s.accept() # look for a connection
+ data = client.recv(size)
+ if data: # if the connection was closed there would be no data
+ print "received: %s, sending back tiny_html"%data
+ client.send(ok_response(html))
+ client.close()
\ No newline at end of file
diff --git a/assignments/week02/lab/http_serve3.py b/assignments/week02/lab/http_serve3.py
new file mode 100644
index 00000000..57af36b1
--- /dev/null
+++ b/assignments/week02/lab/http_serve3.py
@@ -0,0 +1,53 @@
+#!/usr/bin/env python
+
+import socket
+import email
+
+host = '' # listen on all connections (WiFi, etc)
+port = 50000
+backlog = 5 # how many connections can we stack up
+size = 1024 # number of bytes to receive at once
+
+## create the socket
+s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+# set an option to tell the OS to re-use the socket
+s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
+
+# the bind makes it a server
+s.bind( (host,port) )
+s.listen(backlog)
+
+def ok_response(body):
+ return ( "HTTP/1.1 200 OK\r\n"
+ + "Content-Type: text/html\r\n"
+ + "Date: %s\r\n"%(email.Utils.formatdate())
+ + "\r\n"
+ + body )
+
+
+def parse_request(request):
+ line1 = request.split('\r\n')[0].split()
+ requesttype = line1[0]
+ uri = line1[1]
+ return requesttype, uri
+
+f = open('tiny_html.html')
+html = f.read()
+
+while True: # keep looking for new connections forever
+ client, address = s.accept() # look for a connection
+ data = client.recv(size)
+ req, uri = parse_request(data)
+
+ print req, uri
+
+ if req != 'GET':
+ raise ValueError, "The request was not of type GET"
+
+ if data: # if the connection was closed there would be no data
+
+ client.send(html)
+ client.close()
+
+
+
diff --git a/assignments/week02/lab/http_serve4.py b/assignments/week02/lab/http_serve4.py
new file mode 100644
index 00000000..5a12db2c
--- /dev/null
+++ b/assignments/week02/lab/http_serve4.py
@@ -0,0 +1,63 @@
+#!/usr/bin/env python
+
+import socket
+import email, os
+
+host = '' # listen on all connections (WiFi, etc)
+port = 50000
+backlog = 5 # how many connections can we stack up
+size = 1024 # number of bytes to receive at once
+
+## create the socket
+s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+# set an option to tell the OS to re-use the socket
+s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
+
+# the bind makes it a server
+s.bind( (host,port) )
+s.listen(backlog)
+
+def ok_response(body):
+ return ( "HTTP/1.1 200 OK\r\n"
+ + "Content-Type: text/html\r\n"
+ + "Date: %s\r\n"%(email.Utils.formatdate())
+ + "\r\n"
+ + body )
+
+
+def parse_request(request):
+ line1 = request.split('\r\n')[0].split()
+ requesttype = line1[0]
+ uri = line1[1]
+ return requesttype, uri
+
+def resolve_uri(uri):
+ #strip any leading /
+ if uri.startswith('/'): uri = uri[1:]
+ #if directory
+ if os.path.isdir(uri):
+ list_content = os.listdir(uri)
+ return ok_response('\r\n'.join(list_content))
+ #if a file
+ #if not found
+
+ else: raise ValueError, 'URI not found'
+
+
+while True: # keep looking for new connections forever
+ client, address = s.accept() # look for a connection
+ data = client.recv(size)
+ req, uri = parse_request(data)
+
+ print req, uri
+
+ if req != 'GET':
+ raise ValueError, "The request was not of type GET"
+
+ if data: # if the connection was closed there would be no data
+ print data, '\r\n'
+ client.send(resolve_uri(uri))
+ client.close()
+
+
+
diff --git a/assignments/week02/lab/http_serve5.py b/assignments/week02/lab/http_serve5.py
new file mode 100644
index 00000000..3ec64355
--- /dev/null
+++ b/assignments/week02/lab/http_serve5.py
@@ -0,0 +1,69 @@
+ #!/usr/bin/env python
+
+import socket
+import email, os, time
+
+host = '' # listen on all connections (WiFi, etc)
+port = 50000
+backlog = 5 # how many connections can we stack up
+size = 1024 # number of bytes to receive at once
+headers = {'jpg':'image', 'jpeg':'image', 'gif':'image','png':'image', 'ico':'image', 'html':'html', 'txt':'text'}
+## create the socket
+s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+# set an option to tell the OS to re-use the socket
+s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
+
+# the bind makes it a server
+s.bind( (host,port) )
+s.listen(backlog)
+
+def ok_response(body, ty='text/html'):
+ return ( "HTTP/1.1 200 OK\r\n"
+ #+ "Content-Type: %s\r\n"%ty
+ + "Date: %s\r\n"%(email.Utils.formatdate())
+ + "\r\n"
+ + body )
+
+def parse_request(request):
+ line1 = request.split('\r\n')[0].split()
+ requesttype = line1[0]
+ uri = line1[1]
+ return requesttype, uri
+
+def resolve_uri(uri):
+ #strip any leading /
+ if uri.startswith('/'): uri = uri[1:]
+ #if directory
+ if os.path.isdir(uri):
+ list_content = os.listdir(uri)
+ return ok_response('\r\n'.join(list_content))
+ #if a file
+ if os.path.isfile(uri):
+ ctype = uri.split('.')[-1]
+ return ok_response(uri, headers[ctype]+'/'+ctype)
+
+ else: raise ValueError, 'URI not found'
+
+
+while True: # keep looking for new connections forever
+ client, address = s.accept() # look for a connection
+
+ try:
+ data = client.recv(size)
+ req, uri = parse_request(data)
+
+ print req, uri
+
+ if req != 'GET':
+ raise ValueError, "The request was not of type GET"
+
+ if data: # if the connection was closed there would be no data
+ #print data, '\r\n'
+ tosend = resolve_uri(uri)
+ print tosend
+ client.send(tosend)
+ client.close()
+
+ except:
+ time.sleep(0.1)
+
diff --git a/assignments/week02/lab/test.py b/assignments/week02/lab/test.py
new file mode 100644
index 00000000..973121ee
--- /dev/null
+++ b/assignments/week02/lab/test.py
@@ -0,0 +1,53 @@
+ #!/usr/bin/env python
+
+import socket
+import email, os, time
+
+host = '' # listen on all connections (WiFi, etc)
+port = 50000
+backlog = 5 # how many connections can we stack up
+size = 1024 # number of bytes to receive at once
+
+## create the socket
+s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+# set an option to tell the OS to re-use the socket
+s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
+
+# the bind makes it a server
+s.bind( (host,port) )
+s.listen(backlog)
+
+xx = '''
+
+
+ This is a header
+
+ and this is some regular text
+
+
+ and some more
+
+
+
+
+'''
+
+while True: # keep looking for new connections forever
+ client, address = s.accept() # look for a connection
+
+ try:
+ data = client.recv(size)
+
+
+ if data: # if the connection was closed there would be no data
+ #print data, '\r\n'
+ print xx
+ client.send(xx)
+ client.close()
+
+ except:
+ time.sleep(0.1)
+
+
+
+#
\ No newline at end of file
diff --git a/assignments/week02/lab/tiny_html.html b/assignments/week02/lab/tiny_html.html
index 8d4ec08c..d113b802 100755
--- a/assignments/week02/lab/tiny_html.html
+++ b/assignments/week02/lab/tiny_html.html
@@ -6,6 +6,7 @@ This is a header
and some more
+