Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem With Indy TIdTCPClient Reading Thread?

Status
Not open for further replies.

webowner47

Programmer
Nov 26, 2018
16
DZ
I created a thread for continuously reading from the TIdTCPServer, but it blocks all my client form, after a moment will go not responsive.
Maybe the problem with the way i created the thread, anyway here is my code for the thread:


Code:
//---------------------------------------------------------------------------

#ifndef ReadingThreadH
#define ReadingThreadH
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
//---------------------------------------------------------------------------
class TReadingThread : public TThread
{
private:
protected:
	void __fastcall Execute();
public:
	__fastcall TReadingThread(bool CreateSuspended);

    void __fastcall GetServerResponse();

};
//---------------------------------------------------------------------------
#endif

Code:
//---------------------------------------------------------------------------

#include <System.hpp>
#pragma hdrstop

#include "ReadingThread.h"
#include "MainUnit.h"

#pragma package(smart_init)
//---------------------------------------------------------------------------

void __fastcall TReadingThread::GetServerResponse() {
	int msgLength;
	UnicodeString uReceivedMessage;
	if ( ClientMain->IdTCPClient1->Connected() ) {
		msgLength 		 = ClientMain->IdTCPClient1->IOHandler->ReadInt32();
		uReceivedMessage = ClientMain->IdTCPClient1->IOHandler->ReadString(msgLength);
		if ( uReceivedMessage.Length() != 0 ) {
            ClientMain->MessageDisplay1->Lines->Add(uReceivedMessage);
		}
	}
}

__fastcall TReadingThread::TReadingThread(bool CreateSuspended)
	: TThread(CreateSuspended)
{
}
//---------------------------------------------------------------------------
void __fastcall TReadingThread::Execute()
{
	//---- Place thread code here ----
	while ( !Terminated ) {
        Synchronize(&GetServerResponse);
	}
}
//---------------------------------------------------------------------------



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top