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

Kevin Fishburne kevinfishburne at ...1887...
Tue Apr 5 08:41:09 CEST 2011


On 04/05/2011 01:39 AM, Kevin Fishburne wrote:
> Alright, I've transformed all the networking code to the suggested
> solution, and it's so close to working I can smell it. While there is
> more code now, I like it better as it's easier to read (important!).
>
> Some code:
>
>     Dim id As Byte
>     Dim type As Byte
>     Dim data As String
>
>     id = Read #udp As Byte
>     type = Read #udp As Byte
>     If Eof(udp) = False Then data = Read #udp, Lof(udp) - 2
>
> Using "Lof(udp) - 2" as the length seems to remove bytes from the end
> rather than the beginning. I get an unwanted byte at the beginning as well.
>
> Maybe this is a late April Fools joke about endianness? Other than that,
> the whole app is ready to put pixels on the screen again

After checking my code for bugs (none found, knock on wood) and doing 
some experimentation, it looks like sending certain data types using the 
new method works fine, but other data has an extra byte added in front 
of or in-between variables. Any info about what's really happening is 
appreciated.

Again what I'm trying to do is send an ID (Byte), type (Byte), and a 
sequence of arbitrary variables via UDP. When they're received, the ID 
and type are read normally as Bytes into variables and the rest of the 
data is read into a string and stored in an array for later processing. 
The arbitrary variables stored as a string (everything after ID and 
type) are later interpreted via the *@() functions and assigned to 
variables. To do this I just created a different UDP_Write procedure for 
each transaction type so the packets/transactions are properly 
assembled. I've attached some code excerpts if anyone desires greater 
specificity.

In summary of the attachments, the failure basically goes like this:

' Send username and password.
   ' Send the transaction.
   udp.Begin
     Write #udp, id As Byte
     Write #udp, 50 As Byte
     Write #udp, credentials As String ' credentials = 
"myusername,mypassword"
   udp.Send

' Read the username and password.
   id = Read #udp As Byte
   type = Read #udp As Byte
   If Eof(udp) = False Then data = Read #udp, Lof(udp) ' Username and 
password separated elsewhere, not a problem.

data should be "myusername,mypassword" but it actually is 
"^Uanon at ...2571...,mypassword". "\x15" prepends the string, strangely. I 
think this errant byte also precedes any number of datatypes that are 
send separately and later read as a single string. What is this byte, 
and how may I get rid of it?

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

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: Failed Write Data
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20110405/6c86a68c/attachment.ksh>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: Failed Write Example
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20110405/6c86a68c/attachment-0001.ksh>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: Network.UDP_Read
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20110405/6c86a68c/attachment-0002.ksh>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: Network.UDP_Write_*()
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20110405/6c86a68c/attachment-0003.ksh>


More information about the User mailing list