TClientSockte OnRead issue

Please support our Pascal and Delphi advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Oct 2009
Posts: 1
Reputation: ARC1234 is an unknown quantity at this point 
Solved Threads: 0
ARC1234 ARC1234 is offline Offline
Newbie Poster

TClientSockte OnRead issue

 
0
  #1
Oct 29th, 2009
Hi,

I am using delphi 7 TClientSocket Component non blocking socket. When data arrive on socket i have mapped TClientSocke.OnRead to MyRead function.

function MyRead(Socket: TCustomWinSocket)
var
begin
Log('ReadIN......');
//Class variable
MemoryStream := TMemoryStream.Create;
RcvLen := Socket.ReceiveLength;
MemoryStream.SetSize( RcvLen );
MemoryStream.SetSize( Socket.ReceiveBuf( MemoryStream.Memory^, RcvLen ) );
FReceiveNotify( Self, MemoryStream.Memory^, MemoryStream.Size );
Log('ReadOu......');
end;

The problem i am facing is when i read data from socket but did not return from MyRead function and send notifcation to upper layer to process data at the same time I recevie another read and corrupts my MemoryStream object. How it is possible? I did not reales calling thread, then how can another read read came?
What is the mechanis of OnRead is this called from socket from multiple threads.

Please help me out on this.

Regards, IK
Reply With Quote Quick reply to this message  
Reply

Message:



Similar Threads
Other Threads in the Pascal and Delphi Forum


Views: 415 | Replies: 0
Thread Tools Search this Thread



Tag cloud for Pascal and Delphi
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC