944,101 Members | Top Members by Rank

Ad:
Oct 29th, 2009
0

TClientSockte OnRead issue

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ARC1234 is offline Offline
1 posts
since Oct 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Pascal and Delphi Forum Timeline: Innosetup: Find values of variables in debugger
Next Thread in Pascal and Delphi Forum Timeline: USB to Parallel





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC