On 01/16/2011 12:49 PM, Benoît Minisini wrote:
>> Yes, it seems you have convinced me. I have one final question however.
>> Currently a UDP packet is being received as a single string of mixed
>> datatypes. The recipient looks at the value of the first byte to
>> determine the type of packet. Here are some made-up examples of packet
>> contents:
>>
>> Byte=0, String=?, String=?
>> Byte=1, Short=?, Short=?, Float=?, Float=?, Byte=?, Byte=?
>> Byte=2, Byte=?, Byte=?, Float=?, Float=?
>>
>> The three packets have different total sizes and different datatype
>> patterns. The only reliable constant is that first identifying byte.
>> There are hundreds of packet types to minimize bandwidth, each one
>> tailored to a specific purpose.
>>
>> Is it possible for the recipient to load the UDP packet into a structure
>> without knowing which structure it needs to go in to? Basically, if I
>> know the first value in the structure is always a byte, can only that
>> byte be read before dumping the entire thing back into a structure?
> Yes.
>
> Reading and writing are not done the same way with UdpSocket.
>
> When you write a bunch of bytes, one Udp message is made from all the bytes
> and sent.
>
> When something is received from an Udp socket, the data is buffered, and you
> can read it with several READ instructions until EOF is raised.
>
> So, you can do:
>
>       Public Struct Message0
>         ...
>       End Struct
>       
>       Public Sub MyUdpSocket_Read
>       
>         Dim iType As Integer
>       
>         iType = Read #MyUdpSocket As Byte
>       
>         Select Case iType
>           Case 0
>             ReadMessage0
>           Case 1
>             ReadMessage1
>           ...
>         End Select
>       
>       End
>       
>       Private Sub ReadMessage0()
>       
>         Dim tMessage As Message0
>       
>         tMessage = Read #MyUdpSocket As Message0
>         ...
>       
>       End
>       
>       ...
>
>> And yes, I had my first Slashdot article posted yesterday. Ken at Ultima
>> Aiera said he got a record for hits to his site because of it...nice.
> Cool. :-)
>

That is extremely awesome. Thanks for the explanation and example code. 
I'll go ahead and start converting my code, so you'll get no trouble 
from me by removing the functions.

-- 
Kevin Fishburne
Eight Virtues
www: http://sales.eightvirtues.com
e-mail: sa...@eightvirtues.com
phone: (770) 853-6271


------------------------------------------------------------------------------
Protect Your Site and Customers from Malware Attacks
Learn about various malware tactics and how to avoid them. Understand 
malware threats, the impact they can have on your business, and how you 
can protect your company and customers by using code signing.
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user

Reply via email to