socket

socket

Functions

Name Description
create_socket_client Create a socket client and attempt to connect to a specified host and port.

create_socket_client

socket.create_socket_client(host_ip, port, retry_connection_after_s=1)

Create a socket client and attempt to connect to a specified host and port.

This function attempts to establish a TCP connection to the specified host and port. It retries the connection up to a maximum number of times (3) if the connection is refused. If the connection is successful, the socket object is returned.

Parameters

Name Type Description Default
host_ip str The IP address of the host to connect to. required
port int The port number on the host to connect to. required
retry_connection_after_s float The number of seconds to wait between connection attempts, by default 1. 1

Returns

Name Type Description
socket.socket A socket object representing the connection to the host.

Raises

Name Type Description
ConnectionRefusedError If the connection is refused after the maximum number of 3 retries.