Hi all,
I'm relatively new to socket programming. I'm worried about how manage strings in this situation. I think better string library could help me. Have you some good practices, or example, about use Bstrlib and socket ?
Thanks in advance
Mario
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Sockets are a transport for copying blocks of binary data between two programs. The Better String Library is a library that encapsulates strings as blocks of binary data. So the two actually fit perfectly together (there are numerous ways of going wrong if you attempt to simply encode ordinary C strings, or direct unicode data over sockets.)
The Better String Library has stream-IO primitives that enable a bstring to be read from sockets -- you need only implement the relevant bNRead function (which just translates a bunch of paramenters into a socket read) and you can then use the the bStream functions or the bread() function to acquire bstring data over sockets. I have done this myself and its generally not a problem.
However, often with sockets you was to specify fixed length protocols for items read. In this case using balloc() to just make enough space in your bstrings and reading the data directly into the (bstring)->data portion is a reasonable way to go.
From having actually done this stuff myself, I can assure you that bstrings are definately very usable and suitable for holding your data from sockets.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi all,
I'm relatively new to socket programming. I'm worried about how manage strings in this situation. I think better string library could help me. Have you some good practices, or example, about use Bstrlib and socket ?
Thanks in advance
Mario
Sockets are a transport for copying blocks of binary data between two programs. The Better String Library is a library that encapsulates strings as blocks of binary data. So the two actually fit perfectly together (there are numerous ways of going wrong if you attempt to simply encode ordinary C strings, or direct unicode data over sockets.)
The Better String Library has stream-IO primitives that enable a bstring to be read from sockets -- you need only implement the relevant bNRead function (which just translates a bunch of paramenters into a socket read) and you can then use the the bStream functions or the bread() function to acquire bstring data over sockets. I have done this myself and its generally not a problem.
However, often with sockets you was to specify fixed length protocols for items read. In this case using balloc() to just make enough space in your bstrings and reading the data directly into the (bstring)->data portion is a reasonable way to go.
From having actually done this stuff myself, I can assure you that bstrings are definately very usable and suitable for holding your data from sockets.