RTC Forums
November 23, 2024, 08:13:23 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   Home   Help Login Register  
Pages: [1]
  Print  
Author Topic: How to receive "fname" with websocket ?  (Read 4435 times)
earthsbest
RTC License+
****
Posts: 7


« on: June 16, 2017, 10:55:36 AM »

Client-side code like this:
Code:
 
var
  wf:TRtcWSFrame;
begin
  wf:=TRtcWSFrame.Create(wf_Text);
  wf.asText['fname']:='Unit1.pas';
  wf.waPayloadLength:=File_Size(wf.asText['fname']);
  if Client.wSend(wf,'ws-file') then
    MemoAdd(1,'Sending TEXT File in one Frame');
end;

server-side :
Code:
 
procedure TForm1.SockProvWSDataReceived(Sender: TRtcConnection);
var
  wf:TRtcWSFrame;
  fname:string;
begin
  wf:=Sender.wsFrameIn;
  fname:= wf.asText['fname'];
end;
 
But "fname" Always empty.

Regards
 
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #1 on: June 16, 2017, 11:05:58 AM »

Assigning something to the "asText" property (or any other "as..." property) only makes it available locally (for example, from inside local events), but ... it is NOT sent to the other side. WebSocket frames ONLY contain an "Opcode" (wf_Text, wf_Binary, wf_Ping, ...) and an optional "Payload" (raw data), which means that ANYTHING you want to send to the other side (with the exception of the opcode, which can ONLY be used to define the type of the frame) has to be sent as part of the "Payload" data.

In other words, if you wanted to send the name of the file to the other side, you would either have to include that file name as part of your "payload" data, or ... send the file name in a separate frame. How you do it is entirely up to you, but make sure the receiver knows what to expect and how to separate that information.

PS. There are also 3 additional bit-size flags in WebSocket Frames (accessible using the waRSV1, waRSV2 and waRSV3 properties on TRtcWSFrame objects), but these flags are reserved for WebSocket Extensions and should NOT be used at the Application level, unless you are implementing a WebSocket Extension. There is also the "Final" flag (waFinal property), which can be used to send multiple frames containing a single combined payload (see the example where "Text" is being sent in chunks), but ... since Clients could automatically combine continuation frames into a single payload (most WebBrowsers do this automatically), I wouldn't recommend using continuation frames as a way to separate your payload into "logical units" (for example, the first frame containing the file name, with continuation frames containing raw file data). Here is the complete WebSocket specification, it you want more details: https://tools.ietf.org/html/rfc6455

Best Regards,
Danijel Tkalcec
Logged
earthsbest
RTC License+
****
Posts: 7


« Reply #2 on: June 19, 2017, 06:25:24 AM »

Thank you very much Danijel.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.024 seconds with 17 queries.