from typing import IO # Opening a file for writing with open('output.txt', 'w') as file: # Writing data to file file.write('Hello, World!') # Flushing the buffer file.flush()
import socket from typing import IO # Creating a TCP socket s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # Connecting to a remote server s.connect(('www.google.com', 80)) # Sending HTTP request to the server request = b'GET / HTTP/1.1\r\nHost: www.google.com\r\n\r\n' s.send(request) # Flushing the buffer to ensure all data is sent s.sendall(b'\r\n\r\n')In this example, we create a TCP socket and connect to a remote server by specifying the server address and port number. We then send an HTTP request to the server using the `send()` method, and flush the buffer using the `sendall()` method to ensure all the data is sent to the server. Package library: `built-in` (no need to install any external package)