Method Name:
recv
Method Signature:
recv(bufsize[, flags])
Parameters:
bufsize – Number of bytes to read
flags – The flag parameter of recv() function as defined in the Unix manual. Default value is zero.
Return Value:
The data received over an SSLSocket instance as bytes.
Overview:
- The receive method returns the decrypted data from the socket as a bytes object.
- In one go, it reads up to bufsize bytes.
Example:
# Example Python program that reads data from import socket # SSL Context creation # Check for OS X platform # Load the CA certificates used for validating the certificate of the server # Create a socket # Making the socket TLS compliant # Connect to the HTTPS server # Complete the TLS handshake # Form a HTTP request and send it to the server secureSocketInstance.sendall(bytes) # Receive data from server print(data) # TLS shutdown handshake # Close the sockets |
Output:
b'HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nETag: "84238dfc8092e5d9c0dac8ef93371a07:1736799080.121134"\r\nLast-Modified: Mon, 13 Jan 2025 20:11:20 GMT\r\nCache-Control: max-age=86000\r\nDate: Sat, 27 Sep 2025 09:45:41 GMT\r\nContent-Length: 1256\r\nConnection: close\r\nAlt-Svc: h3=":443"; ma=93600\r\n\r\n<!doctype html>\n<html>\n<head>\n <title>Example Domain</title>\n\n <meta charset="utf-8" />\n <meta http-equiv="Content-type" content="text/html; charset=utf-8" />\n <meta name="viewport" content="width=device-width, initial-scale=1" />\n <style type="text/css">\n body {\n background-color: #f0f0f2;\n margin: 0;\n padding: 0;\n font-family: -apple-system, system-ui, BlinkMacSystemFont, "Segoe UI", "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;\n \n }\n div {\n width: 600px;\n margin: 5em auto;\n padding: 2em;\n background-color: #fdfdff;\n border-radius: 0.5em;\n box-shadow: 2px 3px 7px 2px rgba(0,0,0,0.02);\n }\n a:link, a:visite' |