Send a message through an opened TCP connection
Possible errors:
— Can't send the data to the socket
send
@/send
Send a message through an opened TCP connection
Possible errors:
— Can't send the data to the socket
INET@/w5500-inet
An internet connection
SOCKxod/net/socket
A socket
MSGstring
The message to send
SENDpulse
Send the message
DONEpulse
Pulses when the message is successfully sent
SOCK'xod/net/socket
A socket
INET'@/w5500-inet
An internet connection
To use the node in your project you should have the xod-dev/w5500 library installed. Use the “File → Add Library” menu item in XOD IDE if you don’t have it yet. See Using libraries for more info.
C++ implementation
#pragma XOD evaluate_on_pin disable
#pragma XOD evaluate_on_pin enable input_SEND
#pragma XOD error_raise enable
#include <SPI.h>
#include <Ethernet2.h>
node {
void evaluate(Context ctx) {
if (!isInputDirty<input_SEND>(ctx))
return;
auto socket = getValue<input_SOCK>(ctx);
auto client = EthernetClient(socket);
auto msg = getValue<input_MSG>(ctx);
size_t lastWriteSize;
for (auto it = msg->iterate(); it; ++it) {
lastWriteSize = client.write((char)*it);
if (lastWriteSize == 0) {
raiseError(ctx);
return;
}
}
client.flush();
emitValue<output_DONE>(ctx, 1);
emitValue<output_SOCKU0027>(ctx, socket);
emitValue<output_INETU0027>(ctx, getValue<input_INET>(ctx));
}
}