Transmitting CHR$(0) across sockets doesn't work

Previous topic - Next topic

FutureCow

It appears that transmitting CHR$(0) characters via sockets fails. Rather than replicating all the details, please see the forum post which explains the problem with example code.
http://www.glbasic.com/forum/index.php?topic=3753.msg27399#msg27399

Schranz0r

Try this:

"my message to sent via sockets\r\n"
I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

FutureCow

SchranzOr, sorry, that won't help, I'm trying to transmit a binary file, not a text string.

bigsofty

Ive not used the Network commands yet but as GLB uses C strings I believe, so the networking command thinks when it hits a chr(0) then its at the end of the string. i.e. no more data, when it could be midway.

Simplest way is to encode the binary data into text, which for networking can have advantages if combined with simple compression like RLE.

Or simply convert your bytes to an ASCII hex string

EG...

255 15 0 255 = "FF0F00FF"

Then decode it at other end.
Cheers,

Ian.

"It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration."
(E. W. Dijkstra)

MrTAToad

Or even a 3 character decimal number, eg 000028255

FutureCow

I'll probably go with 2 char hex, it means I only have to double the number of bytes sent which is probably the best (easy) solution. It's a lot easier than trying to MIME encode it or something equally as complex. Hopefully there'll be a GLBasic command solution for it at some point down the track.
Thanks for all the suggestions!!!!

Kitty Hello

It was a bug in SOCK_RECV. It's fixed in the next version.