Week 1, Day 1

def send_message(output):
  output.write('Hello, World!\n')

send_message(sys.stdout)
send_message(open('new_file.txt', 'w'))
import socket

# Connect to the other machine and set up the stream
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("www.example.com", 80))
stream = s.makefile('rw')  # At this point, 'stream' is similar to what is returned from 'open'

# "Talk" to the other machine.
stream.write("GET / HTTP/1.0\n")
stream.write("host: www.example.com\n")
stream.write("\n")
stream.flush()

# Listen to the reply
headers = {}
for line in stream:
    if len(line.strip()) == 0:
        break
    parts = line.strip().split(':')
    if len(parts) != 2:
        print(f"WTF: {parts}")
    else:
        key, value = parts
        headers[key] = value

for line in stream:
    print(line.strip())

Networking Basics

SSL