Hi !

Sending is OK although not optimal because of buffering.  At least, be sure
to no close the socket before the sending is done: TWSocket will buffer data
for you (up to the amount of available ram space). It is bette as Angus
said, to send by blocks.

For receiving, you must first receive the line you send before the image, to
get the image size. And then you must receive block by block until you get
the whole image.

You may switch TWSoket from line mode (for the line you sent with the image
size) and the go back to binary mode to receive the rest block by block as
you do.

--
francois.pie...@overbyte.be
The author of the freeware multi-tier middleware MidWare
The author of the freeware Internet Component Suite (ICS)
http://www.overbyte.be




-----Message d'origine-----
De : TWSocket [mailto:twsocket-boun...@lists.elists.org] De la part de
Fatimire
Envoyé : vendredi 10 novembre 2017 20:32
À : ICS support mailing
Objet : [twsocket] Twsocket Problem over Internet.

HI for all, i do a prototype to transfer a imagem overt internet with
Twsocket, but in local network works fine, but when i test with a remote
computer in internet connection the file is sended but dont receive or
receive a image with lost collor.

sending ...
    try
      FMS.Seek(0, soBeginning);
      Form10.wscktsrvr1.Client[0].SendStr('IMAGE:' + IntToStr(FMS.Size) +
sLineBreak);
      Form10.wscktsrvr1.Client[0].Send(FMS.Memory, FMS.Size);
    finally
Receiving ...
if (FIsBiniary) then begin
    iCount := Socket3.Receive(FRcvd + FWritePtr, FFileSize - FWritePtr);
    Inc(FWritePtr, iCount);

    if (iCount = 0) then begin
      FIsBiniary := False;
    end;
    if FWritePtr = FFileSize then begin
      F := TMemoryStream.Create();
      try
        F.Write(FRcvd[0], FFileSize);
        Memo1.Lines.Add('write');
      finally
        oBMP := TBitmap.Create;
        f.Seek(0, soBeginning);
        oBMP.LoadFromStream(F);
        Image1.Picture.Assign(oBMP);
        FreeMem(FRcvd, FFileSize);
        FreeAndNil(oBMP);
        F.Free;
      end;

      FIsBiniary := False;
      Socket3.LineMode := True;
    end;
    Exit;
  end;

  sRcvBuf := Socket3.ReceiveStr.Trim;
  Memo1.Lines.Add(sRcvBuf);

  if (sRcvBuf.StartsWith('IMAGE001:')) then begin
    sRcvBuf := sRcvBuf.Substring(9);
    Memo1.Lines.Add('Size: '  + sRcvBuf);

    FFileSize := StrToIntDef(sRcvBuf, 0);
    FWritePtr := 0;
    GetMem(FRcvd, FFileSize);
    Socket3.LineMode := False;
    FIsBiniary := True;
  end;
end;

someone can help-me ?

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

-- 
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