EugeneK 19 Posted January 31, 2023 Hi We now have method to sending TBytes in socket, can we have the same for receiving? Share this post Link to post
aehimself 396 Posted February 1, 2023 var buffer: TBytes; read: Integer; Begin [...] read := Self.Receive(@buffer[0], Length(buffer)); Share this post Link to post
Fr0sT.Brutal 900 Posted February 1, 2023 Any example when it could be useful? Share this post Link to post
Angus Robertson 574 Posted February 1, 2023 From the notes for ICS V8.70 TWSocket: Added ReceiveTB(var Data : TBytes; MaxLen : Integer = -1) : Integer; where MaxLen is optional, to receive TCP data into a TBytes dynamic array of bytes. Also ReceiveFromTB and ReceiveFrom6TB for UDP datagrams. Receiving into a fixed size buffer is more slightly more efficient, but TBytes has more RTL support for converting to strings, etc. ReceiveTB will resize the variable up to MaxLen. The new functions are used in the OverbyteIcsIpStreamLog unit which how they were tested. Angus Share this post Link to post
Fr0sT.Brutal 900 Posted February 1, 2023 (edited) @TC Just remember the streamed data could be broken into different TCP packets at literally any place. So even converting a chunk to a string is not reliable unless you use 1-byte encodings (no, UTF-8 is not one of them). Otherwise you must use some kind of concatenating buffer/stream which makes TBytes application useless Edited February 1, 2023 by Fr0sT.Brutal Share this post Link to post
aehimself 396 Posted February 1, 2023 9 minutes ago, Fr0sT.Brutal said: Otherwise you must use some kind of concatenating buffer/stream I wrote my helper class for this purpose, it can be used and abused as one feels like it: Maybe it worth to revisit that code, I don't remember what lurks within it's lines. Share this post Link to post
Angus Robertson 574 Posted February 1, 2023 Indeed, the OverbyteIcsIpStreamLog unit builds text lines by parsing a TByte buffer one character at a time. But many quick and dirty programs accept that TCP sends full packets, like my new WebSocket sample. The other advantage of TByte is avoidance of pointer handling, all those @ and ^ symbols that really have no place in modern applications since they can be abused so easily. Ditto the Move function. ICS simply offers alternatives, choose the easiest to use. Angus Share this post Link to post
EugeneK 19 Posted February 1, 2023 Hi Can we also have function that returns TBytes? It is more convenient in many cases Share this post Link to post
Angus Robertson 574 Posted February 17, 2023 Quote Can we also have function that returns TBytes? It is more convenient in many cases This will be in SVN next week, seems simpler but needs an extra line of code to check the TBytes length. Angus 1 Share this post Link to post
EugeneK 19 Posted February 27, 2023 Hi I wonder what is the need for MaxLen parameter? There is no such logic in ReceiveStr functions, if there is more data than MaxLen is it discarded or you can receive it in next call? Share this post Link to post
Angus Robertson 574 Posted February 28, 2023 While ReceiveStr may not have MaxLen, other similar functions do, so it's backward compatible. Since it is defaulted, you can ignore it. Angus Share this post Link to post