tcp

class platypush.plugins.tcp.TcpPlugin(**kwargs)[source]

Plugin for raw TCP communications.

__init__(**kwargs)[source]
close(host: str, port: int)[source]

Close an active TCP connection.

Parameters
  • host – Host IP/name.

  • port – TCP port.

connect(host: str, port: int, timeout: Optional[float] = None)[source]

Open a TCP connection.

Parameters
  • host – Host IP/name.

  • port – TCP port.

  • timeout – Connection timeout in seconds (default: None).

recv(length: int, host: str, port: int, binary: bool = False, timeout: Optional[float] = None) str[source]

Receive data from a TCP connection. If the connection isn’t active it will be created.

Parameters
  • length – Maximum number of bytes to be received.

  • host – Host IP/name.

  • port – TCP port.

  • binary – If set to True then the output will be base64-encoded, otherwise decoded as string.

  • timeout – Connection timeout in seconds (default: None).

send(data: Union[bytes, str], host: str, port: int, binary: bool = False, timeout: Optional[float] = None, recv_response: bool = False, **recv_opts)[source]

Send data over a TCP connection. If the connection isn’t active it will be created.

Parameters
  • data – Data to be sent, as bytes or string.

  • host – Host IP/name.

  • port – TCP port.

  • binary – If set to True and data is a string then will be treated as base64-encoded binary input.

  • timeout – Connection timeout in seconds (default: None).

  • recv_response – If True then the action will wait for a response from the server before closing the connection. Note that recv_opts must be specified in this case - at least length.