Hi,
I need your help.
I'm coding a client/server application and until now I was using SendNetworkString() to communicate. But the string is bigger and bigger (>10mb) so I would like to compress it.
Compress is not a problem (with compressmemory) but sending the data and receiving the data are. I should use SendNetworkData() instead of SendNetworkString() and the receiving is not a simple ReceiveNetworkData() + peekS anymore. I guess I should indicate the size of the compressed data in the packet but I'm a little lost...
Can someone suggest a example of client and server doing compressed data exchange ? Or another solution ?
Thanks for your time.
Need Help : Compress String for SendNetworkString()
Need Help : Compress String for SendNetworkString()
Windows 10 Pro x64
PureBasic 6.04 x64
PureBasic 6.04 x64
- NicTheQuick
- Addict
- Posts: 1226
- Joined: Sun Jun 22, 2003 7:43 pm
- Location: Germany, Saarbrücken
- Contact:
Re: Need Help : Compress String for SendNetworkString()
That's just some bullshit from ChatGPT.labefat181 wrote: ↑Thu Jun 01, 2023 6:41 pm Here is an example of how to compress a string and send it over a network using PureBasic
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
Re: Need Help : Compress String for SendNetworkString()
You could send a header. It contains two longs: packed_size, unpacked_size. When they are both equal size the data is not packed. You send the header who is always 8 bytes long, and receive it the same way on the other size. Once received you read packed_size of bytes before receiving any other message from that connection. On the sender side you send the message (after the header) entirely before sending any other message.
Code: Select all
Structure myHeader
packed_size.l
unpacked_size.l
EndStructure
Procedure SendMyString(Connection, String$)
Protected Header.myHeader
protected str_bytes = StringByteLength(String$)
; compress string
Header\packed_size = packed
Header\unpack_size = str_bytes
SendNetworkData(Connection, @Header, SizeOf(myHeader))
; Send data loop
EndProcedure
Procedure.s ReceiveMyString(Connection)
Protected Header.myHeader
Protected result$
If ReceiveNetworkData(Connection, @Header, SizeOf(myHeader)) = SizeOf(myHeader)
; receive Loop
result$ = space(Header\unpack_size / 2) ; we send packed unicode strings or you have to
; Unpack received data to @result$
EndIf
ProcedureReturn result$
EndProcedure
Re: Need Help : Compress String for SendNetworkString()
...or use one of the notwotk modules floating around here:
http://forums.purebasic.com/english/vie ... hp?t=73882
http://forums.purebasic.com/english/vie ... hp?t=73882
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
Re: Need Help : Compress String for SendNetworkString()
Thank you for your help.
I will try this module.
I will try this module.
Windows 10 Pro x64
PureBasic 6.04 x64
PureBasic 6.04 x64