Now we get to communicate with the server. In retrieving information from a web server, web browsers send their requests in the following format:
<type of request> <file name> <protocol to use>Our web client will ask the server to "GET" a given file using the HTTP 1.0 protocol. To communcate this, we write to the file-like object of the socket instance:
fileobj.write("GET "+filename+" HTTP/1.0\n\n")The server will then respond with the data, and that data will be buffered as a file-like object. But our program will not get it unless we read it. So read the file object into another variable, here called buff.
buff = fileobj.readlines()
