[Gambas-user] gb3 RC1: using structures to replace the loss of Mk$ functions

Benoît Minisini gambas at ...1...
Mon Apr 4 02:46:58 CEST 2011


> I'm finding that the task of replacing the Mk$ functions with structures
> for UDP packet client/server transactions is a massive undertaking. So
> far it's affecting every part of my project that constructs, parses,
> sends and receives data. As a consequence the network code is going from
> dozens of lines to hundreds, and I'm beginning to see that the actual
> logic of network operations will need to be changed as well.
> ...

Finally I come with a solution. Well I hope.

I added three new methods to the Stream class (and so to its child classes: 
File, Socket, UdpSocket...) in revision #3730.

Stream.Begin(), Stream.Send() and Stream.Drop().

All WRITE instructions between a Stream.Begin() and a Stream.Send() will be 
merged, and send in one shot when Stream.Send() is called.

Stream.Drop() just cancels that process.

That way, to forge and send a packet to your UdpSocket, instead of doing 
something like:

	Write #MyUdpSocket, Chr$(42) & MkShort$(A) & MkInt$(B) & MkFloat$(C) 
	& SomeString ...

You will do:

	MyUdpSocket.Begin
	Write #MyUdpSocket, 42 As Byte
	Write #MyUdpSocket, A As Short
	Write #MyUdpSocket, B As Integer
	Write #MyUdpSocket, C As Float
	Write #MyUdpSocket, SomeString, Len(SomeString)
	MyUdpSocket.Send

To read the packet, just use the Read instruction. The UdpSocket already 
buffers the received packet internally.

All that should allow you to do the same thing as before with Mk*() functions, 
with more lines of code, but with endianness support, without adding too much 
code to the interpreter.

Please tell me that you can do something with that, I have a release candidate 
to prepare. :-)

Regards,

-- 
Benoît Minisini




More information about the User mailing list