So I am doing very low-level networking for school, and I wrote a program that uses HTTP to request a file from a server. I could not get the right output on my MacBook in VSCode, so I sent my exact file to a friend who ran it using the same version of Python on his Windows machine in VScode. The code worked exactly how it was supposed to on his computer, but only outputs part of the expected output on mine. Here is the program:
import socket
# Variables
serverIP = 'gaia.cs.umass.edu'
serverPort = 80
BUFFER_SIZE = 262144
messageSent = 'GET /kurose_ross/interactive/index.php HTTP/1.1\r\nHost:gaia.cs.umass.edu\r\n\r\n'
# Attempt to create socket
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print ("Socket successfully created")
except socket.error as error:
print ("socket creation failed with error %s") %(error)
# Connect
s.connect((serverIP, serverPort))
# Send Message
s.send(messageSent.encode())
# Receive Message
messageReceived = s.recv(BUFFER_SIZE).decode()
print(messageReceived)
s.close()