Hi guys, im trayng to send a record with a stream size to send a image.
Example
PCtlCmd = ^TCtlCmd;
TCtlCmd = packed record
Cmd: Byte;
ImageSize: integer;
end;

//SENDING
begin
MemoryStream := TMemoryStream.Create;
img1.Picture.Graphic.SaveToStream(MemoryStream);
MemoryStream.Seek(0, soFromBeginning);
FCCmd.Cmd := 10;
FCCmd.ImageSize := MemoryStream.Size;
WSocketServer1.Client[0].Send(@FCCmd, SizeOf(FCCmd));
WSocketServer1.Client[0].Send(MemoryStream.Memory, MemoryStream.Size);


//receiving
procedure TForm1.WSocket1DataAvailable(Sender: TObject; ErrCode: Word);
var
nLen: Integer;
begin
FPos := 0;
nLen := WSocket1.Receive(@FCmd2[FPos], SizeOf(TCtlCmd2) - FPos);
if (nLen > 0) then
begin
Inc(FPos, nLen);
if (FPos = SizeOf(TCtlCmd2)) then
begin
FPos := 0;
try
case TCtlCmd2(FCmd2).cmd of
10:
begin
ShowMessage(inttostr(TCtlCmd2(FCmd2).cmd));
end;
end;
except end;
end;
end;
end;
But i receing the cmd 10 2 times, why ?


Sent from [ProtonMail](https://protonmail.ch), encrypted email based in 
Switzerland.
-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be

Reply via email to