Skip to content

TCP

The TCP interfaces are used to set up a TCP server or client.

TCPClient

Methods:

Name Description
__init__

Initialize the TCP client.

close

Close the TCP connection.

connect

Connect to the TCP server.

receive

Receive data from the connected server.

send

Send data to the connected server.

__init__(hostname, port)

Initialize the TCP client.

Parameters:

Name Type Description Default
hostname str

The hostname or IP address to connect to.

required
port int

The port number to connect to.

required

close()

Close the TCP connection.

connect()

Connect to the TCP server.

receive(buffer_size=1024)

Receive data from the connected server.

Parameters:

Name Type Description Default
buffer_size int

The maximum amount of data to receive at once (default: 1024).

1024

send(data)

Send data to the connected server.

Parameters:

Name Type Description Default
data

The data to send (bytes).

required

TCPServer

Methods:

Name Description
__init__

Initialize the TCP server.

close

Close the TCP connection.

connect

Accept a connection from a client.

receive

Receive data from the connected client.

send

Send data to the connected client.

__init__(hostname, port)

Initialize the TCP server.

Parameters:

Name Type Description Default
hostname str

The hostname or IP address to bind the server to.

required
port int

The port number to listen on.

required

close()

Close the TCP connection.

connect()

Accept a connection from a client.

receive(buffer_size=1024)

Receive data from the connected client.

Parameters:

Name Type Description Default
buffer_size int

The maximum amount of data to receive at once (default: 1024).

1024

send(data)

Send data to the connected client.

Parameters:

Name Type Description Default
data

The data to send (bytes).

required