Hello Alper,

> I'm using LineMode, to receive all data sent. (My data size is 49b in total
> and no string data in it)
> Are there any conflicts i may encounter in the approach stated below?

Yes, if your binary data contains the line end characters you use the
your code will fail as Arno already mentioned.

Second, if you do not receive your whole data, but only a part of it
then your code will fail too. Also it is possible you receive your whole
packet and a part (or whole) of the next packet (depending on speed of
the transmitting prgram).

> (I intend to replace Rcvd variable with a global one to prevent having
> allocating it in every receive)

Good, allocating each time will slow down and possible to have
fragmented memory if you have hi speed transmission / reception. Not
need to use a global, but a class variable will do the same (but that's
probably what you mean).

>     if RcvdSize < 0 then exit;

You may better change this to:
  if RcvdSize <= 0 then
     Exit;
Because if you receive nothing (0) then you can exit here also.
Somethime Winsock tell to receive and does not wants to give data (I
think Winsock is a women ;-)

>     case Ord(Rcvd[0]) of // Choose data type
>       0: begin
>         New(Data);
>         try
>           CopyMemory(Data, @Rcvd[1], SizeOf(TStatus));

Yes oke, but what if you have just received one byte here? Then this
will fail.

You can use LineMode but then you have to make sure the line end
character(s) you want to use ar never in your data. Several approch ar
possible, Look at my article on 
http://wiki.overbyte.be/wiki/index.php/Sending_and_receiving_data
wich explain some of the possible approaches for binary data.

---
Rgds, Wilfried [TeamICS]
http://www.overbyte.be/eng/overbyte/teamics.html
http://www.mestdagh.biz

Tuesday, June 30, 2009, 18:29, Alper Albayrak wrote:

> Yes, Im using TCP.
> I solved my problem (at least in here) with replacing Move() into
> CopyMemory()

> I'm using LineMode, to receive all data sent. (My data size is 49b in total
> and no string data in it)
> Are there any conflicts i may encounter in the approach stated below?
> (I intend to replace Rcvd variable with a global one to prevent having
> allocating it in every receive)

> Thank you for help and kind replies..

> procedure TMainForm.WSocket1DataAvailable(Sender: TObject; ErrCode: Word);
> var
>   Rcvd: PChar;
>   RcvdSize: integer;
>   Data: PStatus;
> begin
>   if ErrCode <> 0 then exit;
>   GetMem(Rcvd, 128);
>   with (Sender as TWSocket) do
>   try
>     RcvdSize := Receive(Rcvd, 128);
>     if RcvdSize < 0 then exit;

>     case Ord(Rcvd[0]) of // Choose data type
>       0: begin
>         New(Data);
>         try
>           CopyMemory(Data, @Rcvd[1], SizeOf(TStatus));
>           ...
>         except
>           Dispose(Data);
>         end;
>       end;

>       1: begin
>           ...
>           end;
>     end;
>   finally
>     FreeMem(Rcvd);
>   end;
> end;
> --
> 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