#1 2016-10-24 13:16:57

jars
Member
Registered: 2015-05-15
Posts: 29

Lost some bytes sending with websockets

Hi,
Modifying the Project31ChatServer example, I compress some json records with Zlib for compatibility and then call "NotifyBlaBla(pseudo,msg)" where msg is the compressed json.
Once compressed I take volume size to compare with the size received.
What happens is that the client receive fewer bytes than the server sends.
I have no idea how to solve it or because it happens.
Thanks in advance for any help.

Offline

#2 2016-10-24 13:24:28

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,655
Website

Re: Lost some bytes sending with websockets

I guess that the chat server expect text, not binary content.

Offline

#3 2016-10-24 13:32:14

jars
Member
Registered: 2015-05-15
Posts: 29

Re: Lost some bytes sending with websockets

Hi ab,
Then, how can I send this?

Offline

#4 2016-10-24 13:43:19

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,655
Website

Re: Lost some bytes sending with websockets

If you use text transmission, the only possibility is to base-64 encode the compressed content.

You need to use a binary transmission with your WebSockets, like for the TWebSocketProtocolBinary, instead of the TWebSocketProtocolChat protocol, which is text-based.
BTW, TWebSocketProtocolBinary has already built-in compression and encryption available.

Why do you want to reinvent the wheel?

Offline

#5 2016-10-24 13:58:55

jars
Member
Registered: 2015-05-15
Posts: 29

Re: Lost some bytes sending with websockets

Why do you want to reinvent the wheel?

Because I don't know which programming language will use on client-side

Offline

#6 2016-10-24 14:20:27

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,655
Website

Re: Lost some bytes sending with websockets

So, keep with JSON and text protocol, without compression.
It will be safe and easy enough to work with, for any client-side client.

Cross-platform compression is very difficult to implement.
The only possible way may be to implement https://tools.ietf.org/html/rfc7692 but even this is a proposed standard, not widely adopted I'm afraid...

Offline

#7 2016-10-24 14:46:36

jars
Member
Registered: 2015-05-15
Posts: 29

Re: Lost some bytes sending with websockets

I can't keep it without compression because the json size is about 150k.
Is there another way to send this binary data?
I only need to send this data from server to clients.

Last edited by jars (2016-10-24 14:59:09)

Offline

#8 2016-10-24 15:27:28

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,655
Website

Re: Lost some bytes sending with websockets

Long polling may be easier to implement.
But it will depend also on the clients possibilities/technologies used.

But of course, WebSockets binary could be used for that.
Just create your own server side protocol class, taking inspiration from TWebSocketProtocolBinary and TWebSocketProtocolChat.

Offline

Board footer

Powered by FluxBB