Re: [Gambas-user] Problem with READ on a UDP socket
Erm, Ok .. I was expecting a buffer layer between socket library and Gambas .. but that aside, If I'm expecting a binary packet via a UDP socket, for example; type - 1 byte number - 4 bytes size - 2 bytes payload - up to 1024, dictated by size Can anyone tell me in Gambas how I would go about transferring data from the packet to Gambas Variables? READ #$udp,data,lof($udp) Would give me the contents of the packet as a string, but I can't seem to see an effective / efficient way of breaking it down from there .. anyone ? tia Gareth. - Original Message - From: Benoit Minisini [EMAIL PROTECTED] To: mailing list for gambas users gambas-user@lists.sourceforge.net Sent: Tuesday, 4 November, 2008 2:35:21 PM GMT +00:00 GMT Britain, Ireland, Portugal Subject: Re: [Gambas-user] Problem with READ on a UDP socket On mardi 4 novembre 2008, Gareth Bult wrote: Hi, I think I reported this quite a while ago but it still seems to be a problem ... using READ to try to acquire less than the entire available buffer doesn't seem to work .. and if I read the entire buffer, there's no obvious way to break the packet down into it's constituent parts ... Anyone any ideas? (and anyone any idea where the other 24 bytes are going ??) PRIVATE $udp AS UdpSocket PUBLIC SUB _new() $udp = NEW UdpSocket AS Socket $udp.Bind(2000) END PUBLIC SUB Socket_Read() DIM cmd AS Byte DIM siz AS Long PRINT Lof($udp) READ #$udp, cmd, 1 PRINT Lof($udp) 'READ #$udp, siz, 8 = generates error if uncommented END $shell echo R0011Hello World 123 |nc -u localhost 2000 25 0 === should be 24! After having investigated, it seems that this is a property of the UDP sockets. According to the manual page, when you read a message from a socket, If a message is too long to fit in the supplied buffer, excess bytes may be discarded depending on the type of socket the message is received from. You should not have this behaviour if you use a TCP socket. But note that Gambas could be more user-friendly by maintaining an internal message buffer for UDP sockets, so that successive READs in the same event handler work as you expected. I will think about that. Regards, -- Benoit Minisini - This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100url=/ ___ Gambas-user mailing list Gambas-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gambas-user -- Managing Director, Encryptec Limited Tel: 0845 5082719, Mob: 0785 3305393 Email: [EMAIL PROTECTED] Statements made are at all times subject to Encryptec's Terms and Conditions of Business, which are available upon request. - This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100url=/ ___ Gambas-user mailing list Gambas-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gambas-user
Re: [Gambas-user] Problem with READ on a UDP socket
On mardi 4 novembre 2008, Gareth Bult wrote: Erm, Ok .. I was expecting a buffer layer between socket library and Gambas .. but that aside, If I'm expecting a binary packet via a UDP socket, for example; type - 1 byte number - 4 bytes size - 2 bytes payload - up to 1024, dictated by size Can anyone tell me in Gambas how I would go about transferring data from the packet to Gambas Variables? READ #$udp,data,lof($udp) Would give me the contents of the packet as a string, but I can't seem to see an effective / efficient way of breaking it down from there .. anyone ? tia Gareth. Without that buffer, it is brain-fucking: DIM sData AS String DIM pBuffer AS Pointer DIM iType AS Byte DIM iNumber AS Integer ... READ #$udp, sData, Lof($udp) pBuffer = Alloc(len(sData)) WRITE #pBuffer, sData, len(sData) READ #pBuffer, iType READ #pBuffer, iNumber ... Free(pBuffer) I will try to fix that in Gambas 3, then backporting all gb.net fixes to Gambas 2 once they are done. Regards, -- Benoit Minisini - This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100url=/ ___ Gambas-user mailing list Gambas-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gambas-user
Re: [Gambas-user] Problem with READ on a UDP socket
Without that buffer, it is brain-fucking: No, I can live with that solution.. :-) It was using a pointer as a stream that I missed .. Many thanks, Gareth. - Original Message - From: Benoit Minisini [EMAIL PROTECTED] To: mailing list for gambas users gambas-user@lists.sourceforge.net Sent: Tuesday, 4 November, 2008 3:51:14 PM GMT +00:00 GMT Britain, Ireland, Portugal Subject: Re: [Gambas-user] Problem with READ on a UDP socket On mardi 4 novembre 2008, Gareth Bult wrote: Erm, Ok .. I was expecting a buffer layer between socket library and Gambas .. but that aside, If I'm expecting a binary packet via a UDP socket, for example; type - 1 byte number - 4 bytes size - 2 bytes payload - up to 1024, dictated by size Can anyone tell me in Gambas how I would go about transferring data from the packet to Gambas Variables? READ #$udp,data,lof($udp) Would give me the contents of the packet as a string, but I can't seem to see an effective / efficient way of breaking it down from there .. anyone ? tia Gareth. Without that buffer, it is brain-fucking: DIM sData AS String DIM pBuffer AS Pointer DIM iType AS Byte DIM iNumber AS Integer ... READ #$udp, sData, Lof($udp) pBuffer = Alloc(len(sData)) WRITE #pBuffer, sData, len(sData) READ #pBuffer, iType READ #pBuffer, iNumber ... Free(pBuffer) I will try to fix that in Gambas 3, then backporting all gb.net fixes to Gambas 2 once they are done. Regards, -- Benoit Minisini - This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100url=/ ___ Gambas-user mailing list Gambas-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gambas-user -- Managing Director, Encryptec Limited Tel: 0845 5082719, Mob: 0785 3305393 Email: [EMAIL PROTECTED] Statements made are at all times subject to Encryptec's Terms and Conditions of Business, which are available upon request. - This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100url=/ ___ Gambas-user mailing list Gambas-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gambas-user
Re: [Gambas-user] Problem with READ on a UDP socket
On mardi 4 novembre 2008, Benoit Minisini wrote: On mardi 4 novembre 2008, Gareth Bult wrote: Hi, I think I reported this quite a while ago but it still seems to be a problem ... using READ to try to acquire less than the entire available buffer doesn't seem to work .. and if I read the entire buffer, there's no obvious way to break the packet down into it's constituent parts ... Anyone any ideas? (and anyone any idea where the other 24 bytes are going ??) PRIVATE $udp AS UdpSocket PUBLIC SUB _new() $udp = NEW UdpSocket AS Socket $udp.Bind(2000) END PUBLIC SUB Socket_Read() DIM cmd AS Byte DIM siz AS Long PRINT Lof($udp) READ #$udp, cmd, 1 PRINT Lof($udp) 'READ #$udp, siz, 8 = generates error if uncommented END $shell echo R0011Hello World 123 |nc -u localhost 2000 25 0 === should be 24! Can you try your code with Gambas 3? I have changed many things in the gb.net component there, but I didn't backported them to Gambas 2. If it fixes your problem, I will do! Regards, I tested your little code, and I confirm that any read entirely voids the internal socket buffer. I will investigate... -- Benoit Minisini - This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100url=/ ___ Gambas-user mailing list Gambas-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gambas-user
Re: [Gambas-user] Problem with READ on a UDP socket
On mardi 4 novembre 2008, Gareth Bult wrote: Hi, I think I reported this quite a while ago but it still seems to be a problem ... using READ to try to acquire less than the entire available buffer doesn't seem to work .. and if I read the entire buffer, there's no obvious way to break the packet down into it's constituent parts ... Anyone any ideas? (and anyone any idea where the other 24 bytes are going ??) PRIVATE $udp AS UdpSocket PUBLIC SUB _new() $udp = NEW UdpSocket AS Socket $udp.Bind(2000) END PUBLIC SUB Socket_Read() DIM cmd AS Byte DIM siz AS Long PRINT Lof($udp) READ #$udp, cmd, 1 PRINT Lof($udp) 'READ #$udp, siz, 8 = generates error if uncommented END $shell echo R0011Hello World 123 |nc -u localhost 2000 25 0 === should be 24! Can you try your code with Gambas 3? I have changed many things in the gb.net component there, but I didn't backported them to Gambas 2. If it fixes your problem, I will do! Regards, -- Benoit Minisini - This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100url=/ ___ Gambas-user mailing list Gambas-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gambas-user
Re: [Gambas-user] Problem with READ on a UDP socket
On mardi 4 novembre 2008, Gareth Bult wrote: Without that buffer, it is brain-fucking: No, I can live with that solution.. :-) It was using a pointer as a stream that I missed .. Many thanks, Gareth. I have implemented a buffered UdpSocket in the revision #1669 of Gambas 3. If you could try it, it would be great! Regards, -- Benoit Minisini - This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100url=/ ___ Gambas-user mailing list Gambas-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gambas-user