If you want I could send you my File Sender source code. I am too lazy to make an example within a timespan that will suit you, but I will soon. PM me if you want my source.
Printable View
If you want I could send you my File Sender source code. I am too lazy to make an example within a timespan that will suit you, but I will soon. PM me if you want my source.
Jamie, could you please tell me how can I send a stack message with one byte and one short in C++?
I've tried to figure it out myself, but it always seems to lost the last value. For example, if I send a stack with char and short, then MMF reads the char, but it can't read the short properly. And if I send a stack with short and char, then it can read the short, but can't read the char...
I'm sure I'm doing something wrong, so please show me some example on how to do it :)
On the Sender's Side:
Push Byte (some value) onto stack
Push Short (some value) onto stack
On the Receiver's Side:
Get Byte (signed/unsigned) at 0
Get Short (signed/unsigned) at 1
In C++ LB...
EDIT: My guess is that the C++ version of lacewing needs you to send the whole stack in one go, not push element by element. Best wait for Jamie to be sure.
The whole stack/text/number message system is an MMF2 thing. C++ Lacewing just transmits binary buffers with a subchannel and type (0-8). The MMF2 extension uses type 0 for text (ASCII char array), 1 for number (4 byte integer) and 2 for a stack (little endian binary buffer).
Quote:
Originally Posted by Greg
Code:char Message[3];
*(char *) Message = TheByte;
*(short *) (Message + 1) = TheShort;
Channel.Send(Subchannel, Message, 3, 2);
Given that, this might be safer:
It looks more longwinded, but it's safe against sizing errors, and it's much easier to add to the message. Obviously you'd name "struct Message", "Message::theByte", and "Message::theShort" more sensibly, and have different structs for different messages.Code:In a header:
#pragma pack (push, 1)
struct Message
{
char theByte;
short theShort;
};
#pragma pack (pop)
When sending:
Message message;
message.theByte = TheByte;
message.theShort = TheShort;
Channel.Send(Subchannel, &message, sizeof(message), 2);
Thanks, Jamie, now I know how it works :D I've never seen something like *(short*) (Message+1), I wouldn't figure it out by myself xD
Jamie, how about sending a string in a stack? I've tried this:
...but the app crashes then. I've also tried:Code:char Message[3];
string s = "abc";
*(string*)Message = s;
But it doesn't work either.Code:char Message[3];
string s = "abc";
(string)Message = s;
Don't forget that strings are null terminated, so "abc" is actually a b c \0
You can probably do:
string s = "abc";
Channel.Send(Subchannel, s.c_str(), s.size(), 2);
Dynasoft, your solution works, but only if the string is the only thing I send in the stack. I need to send it along with some char and short values.
EDIT:
Nvm, I've already figured it out! Thanks! :)
Jamie,
Could you post an example of how to send a file using lacewing. I tried doing it, and I get the file, but the file that is sent returns 0 kb with no data.
I am confused about position and size.
Position is the position in the stack, which normally is 0 if you are only sending file data, and the size you can get via an expression to get the size of the stack. The easiest thing to do is to create the file with the File Object, then use Lacewing's Append Stack to File action. You can send large files in small chunks, too, which should be some simple math ;)
LB, thanks man.
I will try it out and see if it works. But now it makes sense to me.
-Mike
Hello,
I have a very strange bug.
I try to send (X,Y) to the channel via Stacks, but when the other client received the stack, X is set correctly but Y takes a strange value.
http://s2.noelshack.com/uploads/imag...912227_bug.png
You are reading the short from 1, when really it is at 2. A short has two bytes worth of data. Just change the second parameter to two, where you are changing the Y position, and it should work fine.
Thank you it works fine.
Can you explain me why "A short has two bytes worth of data" ?
Edit : I understood :D Thanks !!!
Jamie, thanks for this! Since Flash isn't capable of UDP, stacks will help quite a bit (I hope!).
That really helped.
It would be nice if the tutorial could be updated. The whole "push" thing confused mein the start.