Open a connection to the desired host. :param address: The address of the host to connect to. :param port: The port of the host to connect to. :return: The socket connected to the host.
(address: str, port: int)
| 42 | |
| 43 | |
| 44 | def open_connection(address: str, port: int) -> socket.socket: |
| 45 | """Open a connection to the desired host. |
| 46 | |
| 47 | :param address: The address of the host to connect to. |
| 48 | :param port: The port of the host to connect to. |
| 49 | :return: The socket connected to the host. |
| 50 | """ |
| 51 | sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
| 52 | sock.connect((address, port)) |
| 53 | print(f'Connected to {address}:{port}') |
| 54 | return sock |
| 55 | |
| 56 | |
| 57 | def send_expect_request(sock: socket.socket, server_hostname: str) -> None: |