Back to Adaptive Vision Library website

You are here: Start » Function Reference » TCP IP » TcpIp_ReadAllText

TcpIp_ReadAllText


Receives text from a connected socket until the other side closes connection.

Syntax

void avl::TcpIp_ReadAllText
(
	avl::SocketId inSocket,
	const atl::Optional<int>& inTimeout,
	atl::Conditional<atl::String>& outText,
	bool& outEof
)

Parameters

Name Type Range Default Description
inSocket SocketId Connected socket ID, will be closed if successfully read.
inTimeout const Optional<int>& 0 - NIL Timeout in milliseconds, block if not specified.
outText Conditional<String>& Received data as textual string, or Nil if the operation was interrupted by timeout.
outEof bool& Indicates whether the operation successfully read data to the end of stream.

Description

Reads all data until the other side stops sending and closes the connection on its side.

The inTimeout input specifies the longest possible waiting time, in milliseconds, for the incoming data to be fully received. When no timeout is specified (set to Auto), the execution is blocking. When the filter execution is terminated by timeout condition no data is returned or removed from the input buffer (Nil is returned instead). In such situation the operation can be retried later. When timeout is et to zero the filter performs a single read attempt and returns immediately when no data is available.

Received bytes are interpreted as UTF-8 encoded text and returned on outText output. When received data is not in a valid UTF-8 encoding an IOError is raised.

outEof output is set to True when data was successfully received and the connection is closed by the other side. This output can be used as a more convenient way to detect end of communication in the application.

This filter can raise IoError when the connection is disruptively broken or when other network-related error occurred.

Hints

  • Connect inSocket with the output of TcpIp_Connect or TcpIp_Accept.
  • Set inTimeout if you want the filter to abort waiting for data after a predefined time.

Multithreaded environment

This function is not guaranteed to be thread-safe. When used in multithreaded environment, it has to be manually synchronized.

See Also