Article View: borland.public.cppbuilder.internet.socket
Article #1521Re: TidTCPServer and disconnections problems
From: Stefano Bonifazi
Date: Sat, 13 Jan 2007 11:34
Date: Sat, 13 Jan 2007 11:34
119 lines
4898 bytes
4898 bytes
Hi Mr. Lebeau!
Thank You for Your reply, and as this is my first post in this New
Year, I wish U every luck in 2007!!!
> It will not crash. It will likely raise a suitable exception, which
> is normal behavior by design. But that is NOT a crash.
I even thought of that at first, but I am used to Exception message to
pop up when some Exception is thrown, instead I only got the Windows XP
window message of request to send debug data to Microsof :(
> Get rid of the exception handler altogether.
Ok I've done that now!
And my code is the following after Ur advices:
__fastcall TNodzServerMainForm::TNodzServerMainForm(TComponent* Owner)
: TForm(Owner)
{
NodzIdTCPServer->ThreadClass=__classid(TNodzClientThread);
}
void __fastcall
TNodzServerMainForm::NodzIdTCPServerExecute(TIdPeerThread *AThread)
{
TNodzClientThread *pNodzThread =
reinterpret_cast<TNodzClientThread*>(AThread);
pNodzThread->Connection->ReadLn("�");
int command=pNodzThread->Connection->ReadInteger(false);
int datasize=pNodzThread->Connection->ReadInteger(false);
AnsiString Data = pNodzThread->Connection->ReadString(datasize);
TUpdateData(AThread,command,Data).Synchronize();
}
class TUpdateData : public TIdSync
{
protected:
CmdType command;
AnsiString &Data;
void __fastcall DoSynchronize()
{
TNodzClientThread*
pNodzThread=reinterpret_cast<TNodzClientThread *>(this);
switch(command)
{
case cmdStringCommand:
if(Data=="Disconnect")
pNodzThread->Connection->Disconnect();
break;
case cmdApplicationLog:
pNodzThread->ClientLogTxt += Data;
pNodzThread->ClientLogNeedUpdate=true;
break;
case cmdSCILog:
pNodzThread->SCILogTxt += Data;
pNodzThread->SCILogNeedUpdate=true;
break;
case cmdSPILog:
pNodzThread->SPILogTxt += Data;
pNodzThread->SPILogNeedUpdate=true;
break;
case cmdCPULog:
pNodzThread->CPULogTxt += Data;
pNodzThread->CPULogNeedUpdate=true;
break;
}
}
public:
__fastcall TUpdateData(TIdThread* AThread,int CT,AnsiString &data)
: TIdSync(AThread),command(CT),Data(data){}
};
class TNodzClientThread: public TIdPeerThread
{
public:
TNodzClientForm *NodzClientForm;
TTabSheet *pTabSheet;
TRichEdit *SPILog;
TRichEdit *SCILog;
TRichEdit *ClientLog;
TRichEdit *CPULog;
AnsiString SysCommandTxt;
AnsiString SCILogTxt;
bool SCILogNeedUpdate;
AnsiString SPILogTxt;
bool SPILogNeedUpdate;
AnsiString CPULogTxt;
bool CPULogNeedUpdate;
AnsiString ClientLogTxt;
bool ClientLogNeedUpdate;
int CommandType;
int LastUpdateTime;
bool NeedUpdate;
__fastcall TNodzClientThread(bool ACreateSuspended);
};
//---------------------------------------------------------------------------
Well at first I did not use TUpdateData, but I have been getting Access
violation Exceptions, so I moved the switch block inside the
Synchronized class, but nothing has changed (( .. before, without
deriving from TIdPeerThread all worked well (before I used to allocate
my class data in a thread safe class, inside the OnConnect event handler
and assigning it to the data member of TIdPeerThread)!! What am I
mistaken with in the new code? I even tried to pass TNodzClientThread
pointer to TUpdateData in its constructor, instead of reinterpreting
this pointer inside TUpdateData method, but nothing changed ((
Thank U!
Stefano
Technical Details
Message-ID:
<45a8c3c4@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<45a7f92c@newsgroups.borland.com> <45a803d7$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,827d16ab792ef887 X-Google-Attributes: gid11508e,public X-Google-Language: ENGLISH,ASCII Date: Sat, 13 Jan 2007 12:34:51 +0100 From: Stefano Bonifazi <stefboombastic@email.it> User-Agent: Thunderbird 1.5.0.9 (Windows/20061207) MIME-Version: 1.0 Newsgroups: borland.public.cppbuilder.internet.socket Subject: Re: TidTCPServer and disconnections problems References: <45a7f92c@newsgroups.borland.com> <45a803d7$1@newsgroups.borland.com> In-Reply-To: <45a803d7$1@newsgroups.borland.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit NNTP-Posting-Host: 80.104.232.193 Message-ID: <45a8c3c4@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1168688068 80.104.232.193 (13 Jan 2007 03:34:28 -0800) Lines: 124 Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail