Re: [twsocket] Twsocket Problem over Internet.

2017-11-11 Thread François Piette
> Your receiving is also likely to fail, LineMode should not be used when
you expect binary data, 

Agreed.

> and makes a program more complex than necessary swapping back and forward
while receiving, checking line end is not very hard. 

Disagreed.
What would be easier for Fatimire is to send the image length a single
integer (4 bytes is probably enough) instead of a text line. It is easier
because the length is fixed. When receiving, it is enough to check if the
first 4 bytes are received and the get the length without further parsing.

The code should be written using pure event driven, without wait loops.

Fatimire should read the following documentation:
 http://wiki.overbyte.eu/wiki/index.php/Asynchronous_Paradigm
 http://wiki.overbyte.eu/wiki/index.php/Sending_and_receiving_data


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




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


Re: [twsocket] Twsocket Problem over Internet.

2017-11-11 Thread Angus Robertson - Magenta Systems Ltd
> I try send by block and have the same problem.
> Sleep(100);

If you changed that to Sleep(5000) it would probably work, but very
slowly   

As I said originally, you should be using the OnDataSent to determine
when the data is sent successfully, not just waiting and assuming the
internet is working perfectly and instantly. 

Your receiving is also likely to fail, LineMode should not be used when
you expect binary data, and makes a program more complex than necessary
swapping back and forward while receiving, checking line end is not
very hard. 

And you need to loop to keep receiving until the whole image has been
arrived, it might take minutes on a slow connection.  And handle the
connection breaking before it's complete. 

Angus



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


Re: [twsocket] Twsocket Problem over Internet.

2017-11-11 Thread François Piette
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