# receive

The asynchronous operation belongs to the family of message-based communication operations. It is used to receive a value from an incoming message port queue.

- The operation can be used on connected ports only.
- The operation has blocking semantics (except when used within an alt statement!) i.e., the TTCN3 program execution is halted until the message matching the criteria described in the value part arrives.
- The operation examines the 1st message on the port queue but extracts this only if the message matches the receiving template
- In case of multiple connections the operation may be restricted to a certain sender.
- The received value and the address of the sender may be stored.

Related keywords:

- address
- any
- create
- from
- modifies
- sender
- system
- value

### port_reference.receive [ ( value_part ) ] [ from address_reference ] [ -> assignment_part ];

- port_reference points out the incoming message port.

- the keywords any port may be used to indicate that messages from any ports will be accepted (see the example 7).

- The receive keyword introduces the message reception.

- value_part is one of the following: (rem.: when omitted, any message will be received)

  - a literal value, a constant, a variable, an expression. (see the example1)
  - a value template (see the example 2)
  - a modified template (see the example 3)

- The optional from keyword is used when a port is connected to several entities and restriction to one communication partner is required.

- address_reference is one of the following:

  - a component reference (cf. create) or the keyword system, in case of one-to-many connections.

  - an address reference (cf. address) , when there are several entities within the system under test .

- assignment_part is one or both of the following:

  - the sender keyword followed by a variable of address or component type to store the address of the sender (see the example 5).
  - the value keyword followed by a variable of the same type as the received message to store the received value (see the example 6).

Example 1: literal value

portibus_PCO.receive (charstring:"abl") from system;

The character string abl is received over the port portibus_PCO from the test system interface. The port is connected to several components.

Example 2: template

portibus_PCO.receive (tr_MeiTemplate);

The template (tr_MeiTemplate) determines what kind of messages will be received.

Example 3: modified template

portibus_PCO.receive (modifies tr_MeiTemplate := {field1 := false});

The modified template (tr_MeiTemplate) determines what kind of messages will be received.

Example 4: any message reception

portibus_PCO.receive;

Any message on port portibus_PCO will be accepted.

Example 5: storing the sender address

portibus_PCO.receive (tr_MeiTemplate) -> sender v_address;

The address of the sender is stored in the variable v_address.

Example 6: storing the received value

portibus_PCO.receive (tr_MeiTemplate) -> value v_ReceivedMessage;

The received message is saved in the variable v_ReceivedMessage.

Example 7: receive on any port

any port.receive (tr_MeiTemplate) -> value v_ReceivedMessage;

The message matching the template tr_MeiTemplate and received on any port is saved to the variable v_ReceivedMessage.

BNF definition of receive