TsgcWebSocketClient | Client Send a Text and Binary Message

WebSocket protocol only allows to types of messages: Text or Binary. But you can't send a binary with text in the same message.

One way to solve this, is add a header to binary message before is sent and decode this binary message when is received.

 

There are 2 functions in sgcWebSocket_Helpers which can be used to set a short description of binary packet, basically adds a header to stream which is used to identify binary packet.

 

Before send a binary message, call method to encode stream.

 


sgcWSStreamWrite('00001', oStream);
TsgcWebSocketClient1.WriteData(oStream);

 

When binary message is received, call method to decode stream.


sgcWSStreamRead(oStream, vID);

The only limitation is that text used to identify binary message, has a maximum length of 10 characters (this can be modified if you have access to source code).