Diferències

Ací es mostren les diferències entre la revisió seleccionada i la versió actual de la pàgina.

Enllaç a la visualització de la comparació

Ambdós costats versió prèvia Revisió prèvia
Següent revisió
Revisió prèvia
info:cursos:pue:python-pcpp1:m4:1.2 [08/01/2024 20:25] – [Obtaining user input] mateinfo:cursos:pue:python-pcpp1:m4:1.2 [05/03/2024 09:09] (actual) – [Requesting a document from a server: continued] mate
Línia 59: Línia 59:
 As you can see, the constructor takes two arguments, both declared within the module. Let us tell you about them: As you can see, the constructor takes two arguments, both declared within the module. Let us tell you about them:
  
-  * the former argument is a domain code (we may use the ''AF_INET'' symbol here to **specify the Internet socket domain** - do you remember?\\We told you about Unix and INET domains in the previous section); as different domains require completely different socket countenance, the target domain has to be known at the moment;+  * the former argument is a domain code (we may use the ''AF_INET'' symbol here to **specify the Internet socket domain** - do you remember?\\ We told you about Unix and INET domains in the previous section); as different domains require completely different socket countenance, the target domain has to be known at the moment;
   * the latter argument is a socket type code (we may use the ''SOCK_STREAM'' symbol here to **specify a high-level socket able to act as a character device** - a device that can handle single characters, as we are interested in transferring data byte by byte, not as fixed sized blocks (e.g., a terminal is a character device, while a disk isn't)   * the latter argument is a socket type code (we may use the ''SOCK_STREAM'' symbol here to **specify a high-level socket able to act as a character device** - a device that can handle single characters, as we are interested in transferring data byte by byte, not as fixed sized blocks (e.g., a terminal is a character device, while a disk isn't)
  
Línia 129: Línia 129:
 === Requesting a document from a server === Requesting a document from a server
 Yes, it's send - look at how we combine it with our code from the previous lesson: Yes, it's send - look at how we combine it with our code from the previous lesson:
-<code ; output>+<code python>
 sock.send(b"GET / HTTP/1.1\r\nHost: " + sock.send(b"GET / HTTP/1.1\r\nHost: " +
           bytes(server_addr, "utf8") +           bytes(server_addr, "utf8") +
Línia 179: Línia 179:
 The argument specifies the maximal acceptable length of the data to be received. If the server's response is longer than this limit, it will remain unreceived. The argument specifies the maximal acceptable length of the data to be received. If the server's response is longer than this limit, it will remain unreceived.
  
-You will need to invoke ''recv()'' again (maybe more than once) to get the remaining part of the data. It's a general practice to invoke '''recv()'' as long as it returns some data.+You will need to invoke ''recv()'' again (maybe more than once) to get the remaining part of the data. It's a general practice to invoke ''recv()'' as long as it returns some data.
  
 There are lots of bad things which can spoil our game. For example, the server may not want to talk with us. There are lots of bad things which can spoil our game. For example, the server may not want to talk with us.
Línia 273: Línia 273:
 In fact, we see two separate parts: In fact, we see two separate parts:
  
-  * the first is the response header. We'll tell you a little secret - the topmost line is the most important, as is says whether the server sent back the requested document or not. Look, there is a very significant three-digit number: ''200''\\ \\ It's your lucky number, as it's the status code. The number ''200'' is your best friend, as it announces that the mission was fully successful and you've got your document. The next few lines describe many important details, but we don't need them now. Skip your focus to the first empty line. It's very momentous as it separates the header from...+  * the first is the response header. We'll tell you a little secret - the topmost line is the most important, as is says whether the server sent back the requested document or not. Look, there is a very significant three-digit number: ''200''.\\ It's your lucky number, as it's the status code. The number ''200'' is your best friend, as it announces that the mission was fully successful and you've got your document. The next few lines describe many important details, but we don't need them now. Skip your focus to the first empty line. It's very momentous as it separates the header from...
   * the document. Yes, this is the place where it starts. It may very bloated (it usually is) and we don't want to present it in full.\\It's not important now. We're not going to study HTML. Not here, anyhow.   * the document. Yes, this is the place where it starts. It may very bloated (it usually is) and we don't want to present it in full.\\It's not important now. We're not going to study HTML. Not here, anyhow.
  
  • info/cursos/pue/python-pcpp1/m4/1.2.1704741907.txt.gz
  • Darrera modificació: 06/07/2026 18:29
  • (edició externa)