User Tag List

Page 1 of 6 1 2 3 ... LastLast
Results 1 to 10 of 59

Thread: Binary messages

  1. #1
    Clicker Multimedia Fusion 2 DeveloperSWF Export Module

    Join Date
    Jun 2006
    Posts
    6,773
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Binary messages

    [size:17pt]Binary messages[/size]

    Since they're something I'm often being asked about, and something not many people seem to understand, in this article I'm going to explain how binary messages work in Lacewing. (sorry about the weird formatting, something bad happened to the spaces when transferring it to the forum...)

    [size:14pt]Why should I use binary messages?[/size]

    I guess if you're reading this article, you're probably currently doing things the Moo way and sending delimited strings to be parsed on the receiving end with String Parser.

    Let's imagine we have a networked application that has to send two numbers (perhaps X and Y coordinates?) - it sends them like this:

    104,178

    That string is 7 characters in length, which means Lacewing will use (excluding headers) seven bytes of bandwidth to transmit it. If we were using binary messages instead, this could be sent in only TWO bytes (or four if the numbers were larger than 255).

    How? Well, each character in a string (letter, string, or number) is represented by an ASCII number (search for an "ASCII table" to see which numbers are used for different characters). The character that represents the number "1" is character number 49, the number "0" is character number 48. To send a string, Lacewing uses 1 byte (a byte can be any number from 0 to 255) per character. So the string above would be sent like this:



    Which means the seven bytes:



    are transmitted over the network. This is obviously a complete waste of bandwidth, because all we want to send is two numbers (104 and 178). Lacewing, thankfully, allows you to send the numbers directly, instead of sending a string, and that's what the binary message feature does.

    That means you can send these bytes instead:



    And read them on the other end. Considering how frequently you're likely to be sending messages, this can save a lot of bandwidth.

    [size:14pt]How do I use binary messages?[/size]

    I'll show an example of how to send the two numbers we were talking about above, and read them on the other end.

    [size:11pt]Sending the binary message[/size]

    Old code

    Lacewing : Send text Str$(104) + "," + Str$(178) to channel on subchannel 0

    New code

    Lacewing : Push byte 104
    Lacewing : Push byte 178
    Lacewing : Send binary to channel on subchannel 0

    [size:11pt]Receiving the binary message[/size]

    Old code

    + On text channel message on subchannel 0
    - String Parser : Set source string to Received$("Lacewing")
    - Active : Set X position to Val(listGetAt$("String Parser", 0))
    - Active : Set Y position to Val(listGetAt$("String Parser", 1))

    New code

    + On binary channel master on subchannel 0
    - Active : Set X position to Byte("Lacewing", 0)
    - Active : Set Y position to Byte("Lacewing", 1)

    And that's about it, as far as sending and receiving a message composed of bytes goes. Here's the catch: A byte can only hold a value from 0 to 255 (when you use the expression to read it as unsigned) or from -128 to 127 (when you use the expression to read it as signed). If you want values beyond this range, you'll have to use one of the other data types.

    Lacewing allows you to write and read the following types from binary messages:



    It's quite easy to understand how to use all of these types in your binary messages, providing you understand how Lacewing builds binary messages. When you add something to the binary to send:



    You could now send the binary, and then on the receiving end, read the respective type at the respective index. So if you read an integer at 3, you'd get 31333337. If you read a byte at 7, you'd get 100. Basically, the position of everything in the binary starts at 0 (the first thing you add will always be at index 0) and from there, the index depends on how big the things you added afterwards were.

    If we sent the binary above, containing the numbers 3, 572, 31333337 and 100, it would be 7 bytes in size. If you sent this as a delimited string "3,572,31333337,100", it would be 18 bytes total. This should give you an impression of how much space you can save using the binary messages with Lacewing.

    I hope if binary messages previously made no sense to you, they make a little more now. Good luck

  2. #2
    Clicker

    Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleUniversal Windows Platform Export ModuleSWF Export ModuleXNA Export ModuleInstall Creator Pro
    nivram's Avatar
    Join Date
    Jul 2006
    Location
    Bandon, Oregon
    Posts
    6,731
    Mentioned
    9 Post(s)
    Tagged
    0 Thread(s)

    Re: Stack messages

    This is good. Thanks Jamie.

    Marv
    ​458 TGF to CTF 2.5+ Examples and games
    http://www.castles-of-britain.com/mmf2examples.htm

  3. #3
    Forum Moderator Multimedia Fusion 2 DeveloperAndroid Export ModuleiOS Export ModuleSWF Export ModuleXNA Export Module
    DizzyDoo's Avatar
    Join Date
    Oct 2006
    Location
    South England
    Posts
    718
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Stack messages

    Oh Jamie. I spent a good few hours doing tests with stacks and Lacewing so I could finish my video tutorial series with Lacewing, and you write this. Couldn't you have written this article three days ago! Good stuff though.
    Cranktrain - Currently finishing a new game called The Cat Machine!
    @MattLuard on Twitter.

  4. #4
    Clicker Multimedia Fusion 2 DeveloperSWF Export Module
    NeoMonkey's Avatar
    Join Date
    Oct 2008
    Location
    Finland
    Posts
    129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Stack messages

    How about sending text, how do I count them?

  5. #5
    Clicker Multimedia Fusion 2 DeveloperSWF Export Module

    Join Date
    Jun 2006
    Posts
    6,773
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Re: Stack messages

    They take up the length of the string in bytes. You probably want to push a short with the length beforehand or something.

    To avoid trouble, you could push the string at the end of the stack, so you can just subtract the size of the things before it from the total stack size to work out the string length.

  6. #6
    Clicker Multimedia Fusion 2 DeveloperiOS Export ModuleSWF Export ModuleUnicode Add-on

    Join Date
    Jun 2006
    Location
    Australia
    Posts
    988
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Stack messages

    Really great article! Thanks

  7. #7
    Clicker Multimedia Fusion 2 DeveloperSWF Export Module
    NeoMonkey's Avatar
    Join Date
    Oct 2008
    Location
    Finland
    Posts
    129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Stack messages

    Thanks! Great article BTW!

  8. #8
    No Products Registered

    Join Date
    Nov 2009
    Posts
    480
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Stack messages

    Hi,

    Can anyone please post an example of sending a string with a stack, I get how to send the numbers, but the strings are confusing me.

    -Thanks, Variant

  9. #9
    Clickteam Clickteam
    LB's Avatar
    Join Date
    Jun 2007
    Location
    Richardson, Texas, North America
    Posts
    8,937
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Re: Stack messages

    Could you please say exactly what about them is confusing you??
    Working as fast as I can on Fusion 3

  10. #10
    No Products Registered

    Join Date
    Nov 2009
    Posts
    480
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Stack messages

    Just the part about sending and receiving strings with a stack.

    -Thanks, Variant

Page 1 of 6 1 2 3 ... LastLast

Similar Threads

  1. RPG-like Text Messages
    By Corlen in forum Multimedia Fusion 2 - Technical Support
    Replies: 0
    Last Post: 9th June 2012, 04:18 PM
  2. Help Messages
    By Pixzel in forum Multimedia Fusion 2 - Technical Support
    Replies: 1
    Last Post: 25th March 2011, 11:43 PM
  3. Sphax Messages Box
    By Jeff in forum Released Extensions
    Replies: 3
    Last Post: 9th April 2009, 11:14 AM
  4. Encrypting messages in Moo
    By Plooscva in forum Multimedia Fusion 2 - Technical Support
    Replies: 6
    Last Post: 24th February 2007, 12:49 PM
  5. Messages Box object - Bug
    By Gustav in forum File Archive
    Replies: 9
    Last Post: 26th November 2006, 04:29 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •