[Gambas-user] MkXXX$() functions
Benoît Minisini
gambas at ...1...
Sun Jan 16 18:49:51 CET 2011
>
> 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. :-)
--
Benoît Minisini
More information about the User
mailing list