I want to implement a Delphi WebSocket server to send binary data (Stream and byte array) to javascript client. This could be done after receive a client message OR EVEN as unidirectional message so no client message need to be received. Below the pseudocode.
var
WSServer: TWSocketServer;
Case A: I want to send back the binary data after receive a message
WSServer.OnClientConnect := procedure (Sender: TObject; Client: TWSocketClient; Error: Word)
begin
TWebSockSrvClient(Client).OnWebSocketMessage := WebSocketMessage;
end;
procedure WebSocketMessage(Sender: TObject; Msg: string);
var
MemStream: TMemoryStream;
SocketConn: IWebSocketConnection;
begin
//create and populate MemStream
if (Msg = 'A') then
begin
SocketConn := TWebSocketSocket(Sender).getConnection;
//I need to send back the MemStream but I found only these method:
//SocketConn.sendString
//SocketConn.sendFrame
//SocketConn.sendMessage
end;
end;
Case B: send binary data to some client from button click
procedure TForm1.btnSendBufferClick(Sender: TObject);
var
ArrB: TBytes;
begin
ArrB := [1, 2, 3];
//I tried WSServer.Client[0].SendTB(ArrB) but is doesn't work
end;
I check OverbyteIcsWebSocketSrv.dpr demo but only strings are send.
Any advice?