Copyright VirtualSim 2004-2020 - All rights reserved
LAN
Concept
How to Use
Each message sent or received through a SockItem must have a predefined header made of two integers (so 8 bytes), organized as this:
unsigned short source, type;
unsigned int size;
Source is the any value used to qualify the message provider (is several devices are writing into the same port).
Type: specify the type of the message for casting it properly
Size: is the total length in bytes of the message, for reading the buffer correctly.
So, all user data structure that must be passed or read through a SockItem must be defined as a class inheriting from a base class (MsgData) of vsTASKER.
This base class can be found in /include/engine/vt_sockets.h
For example, if a message must be made of a character string and a value, it should be defined this way:
class myMessage : public MsgData
{
public: myMessage() { size = sizeof(*this); type = 123; }
char label[20];
float value;
};
Then, sending such a message would be done, from a SockItem code, like that:
MyMessage my_mess;
strcpy(my_mess.label, "foo");
my_mess.value = 12.332;
send(my_mess);
And receiving such a message from outside would be done, in a SockItem,like that: