Allow Ascii character 0 in strings
Allow Ascii character 0 in strings
Hi,
the main reason for this is to allow conversion from one type to another.
For instance take long int value 5, converted to a four byte value it would become, chr(0)+chr(0)+chr(0)+chr(5). When return from a bank to the string all we get is chr(5).
The reason I ask this is compression for networking is simpler if you can take a value in the billions and convert it to four bytes for sending over a network this is also true for floats. It seems some characters are ignored by strings in PB, the main characters PB needs to act upon is simply chr(10) and chr(13) nothing more the rest should be sent to the application for use.
Using Val/Str/Hex it takes eight bytes to represent the longint where if converted it would be four in networking this is a waste of bandwidth and on a MMO it could result in lag.
Would this be possible?
the main reason for this is to allow conversion from one type to another.
For instance take long int value 5, converted to a four byte value it would become, chr(0)+chr(0)+chr(0)+chr(5). When return from a bank to the string all we get is chr(5).
The reason I ask this is compression for networking is simpler if you can take a value in the billions and convert it to four bytes for sending over a network this is also true for floats. It seems some characters are ignored by strings in PB, the main characters PB needs to act upon is simply chr(10) and chr(13) nothing more the rest should be sent to the application for use.
Using Val/Str/Hex it takes eight bytes to represent the longint where if converted it would be four in networking this is a waste of bandwidth and on a MMO it could result in lag.
Would this be possible?
- Kaeru Gaman
- Addict
- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
*emptied*
Last edited by Kaeru Gaman on Thu Oct 02, 2008 10:26 pm, edited 1 time in total.
oh... and have a nice day.
- Kaeru Gaman
- Addict
- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
I can totally see the need for that...Kaeru Gaman wrote:I'm sorry, seemed to be the drop to let the barrel overflow...
edited my above post.

EdzUp, there is no technical difference between sending a long/float (4 bytes) directly and sending it as a string. In both cases 4 bytes of binary data will be sent over the connection.
Here is how to send the data directly:
Code: Select all
Global Longvariable.l
Global Floatvariable.f
Global DoubleVariable.d
SendNetworkData(ClientID, @Longvariable, 4)
SendNetworkData(ClientID, @FloatVariable, 4)
SendNetworkData(ClientID, @DoubleVariable, 8)
Yep, the question seems to be: why using a string to communicate? Why not directly send the data itself?
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
( The path to enlightenment and the PureBasic Survival Guide right here... )
-
- User
- Posts: 76
- Joined: Wed Sep 17, 2008 3:10 am
- Location: New Zealand
I think I can answer that, and I know where the author of this thread is coming from, because I tried the very same thing myself.blueznl wrote:Yep, the question seems to be: why using a string to communicate? Why not directly send the data itself?
My idea was to send all types of data for a multiplayer application in a single line, with the server just quickly parroting the data back to all the other clients but the one who sent it, whereupon the clients filter the string to the right handling routine based upon the first character stored in the string.
Alas this didn't work because most ascii characters below value 32 were not being recognised... so I now have to do it the long way with individual byte, float, word, long, and string buffers for the server to filter out and then resend the data on it's way

Simple image a packet system where you need to send:
ClientID[longint]
ClientFrom[longint]
Message Class[longint]
MessageID[Longint]
important[1byte]
Message[random length]
Now if you sent it as you suggest it would come through in random integers so there is no way of knowing who its from. If there was an adjustment to the string it a new 'raw' data type it would be easier to send network data.
ClientID[longint]
ClientFrom[longint]
Message Class[longint]
MessageID[Longint]
important[1byte]
Message[random length]
Now if you sent it as you suggest it would come through in random integers so there is no way of knowing who its from. If there was an adjustment to the string it a new 'raw' data type it would be easier to send network data.
Re: Allow Ascii character 0 in strings
Strings in PureBasic are 0-byte terminated, just like C. This is not going to
change, as stated by both Fred and Freak in the hundreds of requests just
like this in the past. Get over it. Do a search and you'll see their reasons.
change, as stated by both Fred and Freak in the hundreds of requests just
like this in the past. Get over it. Do a search and you'll see their reasons.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
"PureBasic won't be object oriented, period" - Fred.
If you send it as a string it will still be recieved as random integers. You can find out who it's from by checking EventClient() or packing the data into a structure and sending it all at once:EdzUp[SD] wrote:Now if you sent it as you suggest it would come through in random integers so there is no way of knowing who its from.
Code: Select all
Structure Package
SenderID.l
Message.l
EndStructure
Var.Package\SendID = 1234
Var\Message = 9876
SendNetworkData(ConnectionID, @Var, SizeOf(Package))
- Kaeru Gaman
- Addict
- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
Procedures always return a Register.
this CAN be used as a pointer to a String, but it also could be used as a pointer to a not-null-terminated buffer.
just get familiar with Allocated Memory, fixedlength Buffers, etc.
there is no need to and no gain in messing around with strings for non-string issues.
this CAN be used as a pointer to a String, but it also could be used as a pointer to a not-null-terminated buffer.
just get familiar with Allocated Memory, fixedlength Buffers, etc.
there is no need to and no gain in messing around with strings for non-string issues.
oh... and have a nice day.