Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Recv. Packets in another Thread (IdTCPClient)

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Reak
I post too much
Reputation: 0

Joined: 15 May 2007
Posts: 3496

PostPosted: Sun May 18, 2008 6:02 pm    Post subject: Recv. Packets in another Thread (IdTCPClient) Reply with quote

Hello,

Hence the IdTCPClient Socket has no OnRead function I need to recvice packets in an endless loop.
But this will of course freeze my program if I would do it in the main-thread.

So I have to create another.
I never worked with threads before and wanted to try it out now!
So I used BeginThread() on the Form.OnCreate procedure.

Here is my thread-procedure:
Code:
procedure test();
var
  packet: TPacket;
begin
WaitForInputIdle(0, 10000);
Form1.Memo1.Lines.Add('a');
repeat
if not Form1.Client.Socket.Connected then exit;
    try
      Form1.Client.Socket.Recv(packet, sizeof(packet));
      case packet.header of
        01: Form1.LoginPacket(packet);
      end;
    except
      Form1.Memo1.Lines.Add('.');
    end;
until
cclose = true;
end;


But as soon as the program started I got erros.
So I googled and found out that threads are VCL-unsafe.

No I'm wondering how I could slove this problem, any ideas?
Back to top
View user's profile Send private message
Renkokuken
GO Moderator
Reputation: 4

Joined: 22 Oct 2006
Posts: 3249

PostPosted: Sun May 18, 2008 6:35 pm    Post subject: Reply with quote

Use the TThread class.
If it's not a VCL-based form, have it process recv in the idle time of the message pump. There's probably a way to have that situated in the huge list of event handlers for delphi, but I'm not so in-tune with it anymore.
Back to top
View user's profile Send private message
Reak
I post too much
Reputation: 0

Joined: 15 May 2007
Posts: 3496

PostPosted: Mon May 19, 2008 7:44 am    Post subject: Reply with quote

Thanks Renko Very Happy
I've found a TUT about it and I got it working.
But if I close the client while I'm running it in debugging-mode in delphi I'm getting weird errors because of the thread. (Some random adress-violations).

Why? (Source is attached)



The Extension 'rar' was deactivated by an board admin, therefore this Attachment is not displayed.

Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites