TP4 Flashcards
Complete the Proxy.py code:
def producer(queue, baseURL, movieName, track_num):
manifest_url = ________________________________________
response = requests.get(____________)
manifest = ____________
track_num = int(track_num) # Process the manifest offsets = [ ] i = 0 num_fragments = 50 current_track = 0 current_segment = 0
def producer(queue, baseURL, movieName, track_num):
manifest_url = baseURL + ‘/’ + movieName + ‘/manifest.txt’
response = requests.get(manifest_url)
manifest = response.content.decode()
track_num = int(track_num) # Process the manifest offsets = [ ] i = 0 num_fragments = 50 current_track = 0 current_segment = 0
Complete the Proxy.py code:
for j in range(____________________):
segment_url = baseURL + ‘/’ + movieName + ‘/’ + track
headers = {__________________________________________________________}
response = requests.get(__________,____________)
for chunk in response.iter_content(__________):
queue.put(_________)
for j in range(num_fragments):
segment_url = baseURL + ‘/’ + movieName + ‘/’ + track
headers = {“Range”: “bytes=” + str(offsets[j][0]) + “-“ + str(offsets[j][1])}
response = requests.get(segment_url, headers=headers)
for chunk in response.iter_content(CHUNK_SIZE):
queue.put(chunk)
Complete the Proxy.py code:
def consumer(queue, player_socket):
while True:
segment = queue.get()
player_socket._________(_________)
if segment == b’’:
break
def consumer(queue, player_socket):
while True:
segment = queue.get()
player_socket.sendall(segment)
if segment == b’’:
break
Complete the Proxy.py code:
producer_thread = threading.Thread(target=_________, args=(______, ________, _________, _____))
consumer_thread = threading.Thread(target=_________, args=(_____, _________))
producer_thread._______()
consumer_thread.______()
producer_thread.\_\_\_\_\_() consumer_thread.\_\_\_\_\_\_()
producer_thread = threading.Thread(target=producer, args=(queue, baseURL, movieName, track))
consumer_thread = threading.Thread(target=consumer, args=(queue, player_socket))
producer_thread.start()
consumer_thread.start()
producer_thread.join() consumer_thread.join()
what’s the server function?
it is a standard http server that contains movies to be played.
what’s the proxy function?
Has two parts each executed by a thread; the two threads share a queue or buffer.
o Thread producer: gets segments from the content server using a TCP socket TC and
the HTTP protocol and puts them in the queue.
o Thread consumer: gets segments from the queue and writes its content to socket TP
what’s the client function?
shows the movie. Receives the byte stream through a socket TP
which http command do we use in this project?
GET HTTP