Professional Documents
Culture Documents
3.14.15 (-Day)
0 Python Refresher
Last time, HTTP Requests were discussed and a few examples were made to display the requests in
Mozilla Firefox and/or Google Chrome. This time, a bit of python programming is due, let's do the
same thing we did in the previous session, but using a little bit of python programming! So here are a
few refreshers/cheat sheets. Next, we will start playing with a few py scripts.
https://perso.limsi.fr/pointal/_media/python:cours:mementopython3-english.pdf
http://overapi.com/python/
1/4
PUA SRG
3.14.15 (-Day)
2/4
PUA SRG
3.14.15 (-Day)
https://docs.python.org/3.4/howto/urllib2.html#headers
3/4
PUA SRG
3.14.15 (-Day)
s = socket.socket()
host = socket.gethostname()
port = 12345
s.bind((host, port))
#
#
#
#
s.listen(5)
# Now wait for client connection.
while True:
c, addr = s.accept()
# Establish connection with client.
print('Got connection from', addr)
c.send('Thank you for connecting'.encode())
c.close()
# Close the connection
s = socket.socket()
# Create a socket object
host = socket.gethostname() # Get local machine name**
port = 12345
# Reserve a port for your service.
s.connect((host, port))
print(s.recv(1024).decode())
s.close
# Close the socket when done
http://www.tutorialspoint.com/python/python_networking.htm
**Try using something different than hostname to listen on, try using 'localhost' or '127.0.0.1'
6 Project
Now that we have used python to send and receive requests, and even communicate with simple
servers, it is time to do something useful with that information.
Start suggesting project ideas with brief description/details. We need to do this fast so that you can start
working on your idea, nothing major, simple ideas. By next time, each member should submit at least
an initial version of the code in python implementing his/her idea.
4/4