send

xod/w5500/send

Send a message through an opened TCP connection
send
@/send
Send a message through an opened TCP connection
SOCKxod/net/socket
A socket
MSGstring
The message to send
SNDpulse
Send the message
send
DONE
ERR
SOCK
MSG
SND
ERRpulse
Pulses when sending failed (for example, the connection is not open)
DONEpulse
Pulses when the message is successfully sent

C++ implementation

{{#global}}
#include <SPI.h>
#include <Ethernet2.h>
{{/global}}

struct State {
};

{{ GENERATED_CODE }}

void evaluate(Context ctx) {
    if (!isInputDirty<input_SND>(ctx))
        return;

    auto client = EthernetClient(getValue<input_SOCK>(ctx));
    auto msg = getValue<input_MSG>(ctx);

    size_t lastWriteSize;

    for (auto it = msg->iterate(); it; ++it) {
        lastWriteSize = client.write((char)*it);
        if (lastWriteSize == 0) {
            emitValue<output_ERR>(ctx, 1);
            return;
        }
    }

    client.flush();

    emitValue<output_DONE>(ctx, 1);
}