Z
So, nun hab ich alle Indy Komponenten im Thread untergebracht und die Verbindung zum Server lässt sich aufbauen. Siehe da die Form hängt nicht mehr Aber da sind noch ein paar Fragen offen:
//Threadheader:
TIdTCPClient *Client;
TIdSSLOptions *options;
TIdSSLIOHandlerSocket *SSL;
//---------------------------------------------------------------------------
void MyThread::SetName()
{
THREADNAME_INFO info;
info.dwType = 0x1000;
info.szName = "MyThread";
info.dwThreadID = -1;
info.dwFlags = 0;
Client = new TIdTCPClient(Form1); //Warum Form1 und nicht this ??
SSL = new TIdSSLIOHandlerSocket(Form1);
Client->IOHandler = SSL;
Synchronize(GetClientSettings);
__try
{
RaiseException( 0x406D1388, 0, sizeof(info)/sizeof(DWORD),(DWORD*)&info );
}
__except (EXCEPTION_CONTINUE_EXECUTION)
{
}
}
//---------------------------------------------------------------------------
void __fastcall MyThread::GetClientSettings()
{
index = Form1->ComboBox10->Text.Pos(":");
if(index > 0 && index + 1 <= Form1->ComboBox10->Text.Length())
{
temp = Form1->ComboBox10->Text;
port = temp.SubString(temp.Pos(":") + 1,temp.Length() - temp.Pos(":"));
Client->Port = StrToInt(port);
Client->Host = Form1->ComboBox10->Text.SubString(1,Form1->ComboBox10->Text.Pos(":") - 1);
options = SSL->SSLOptions;
if(Form1->ComboBox11->Text == "SSLv2")
options->Method = sslvSSLv2;
else
if(Form1->ComboBox11->Text == "SSLv3")
options->Method = sslvSSLv3;
else
if(Form1->ComboBox11->Text == "TLSv1")
options->Method = sslvTLSv1;
}
else
{
Client->Host = Form1->ComboBox10->Text;
Client->Port = 14888;
Form1->ComboBox10->Text = Form1->ComboBox10->Text + ":14888";
options = SSL->SSLOptions;
if(Form1->ComboBox11->Text == "SSLv2")
options->Method = sslvSSLv2;
else
if(Form1->ComboBox11->Text == "SSLv3")
options->Method = sslvSSLv3;
else
if(Form1->ComboBox11->Text == "TLSv1")
options->Method = sslvTLSv1;
}
}
//---------------------------------------------------------------------------
void __fastcall MyThread::Execute()
{
SetName();
Client->Connect(5000);
while(!Terminated)
{
ClientReceive();
Synchronize(Compute);
if(Client->Connected() == false)
Terminate();
}
}
//---------------------------------------------------------------------------
void __fastcall MyThread::ClientReceive()
{
if(Client->Connected())
{
Client->ReadBuffer(Buff,1024);
}
}
//----------------------------------------------------------------------------
void __fastcall MyThread::Compute()
{
if(strcmp(Buff,"TCP") == 0) //--------Link Server Message
{
TCP_Message *msg = (TCP_Message *)Buff;
if(strcmp(msg->Msg,"BYE") == 0)
{
Form1->Memo1->Lines->Add(String(Date()) + " " + String(Time())+" Login data wrong");
}
else
if(strcmp(msg->Msg,"HELLO") == 0)
{
Form1->Memo1->Lines->Add(String(Date()) + " " + String(Time())+" Login data ok");
}
Wenn euch was böses auffällt dann sagt mir bitte Bescheid. Wie schreibt man sich z.B. die OnConnect, OnDisconnect events eines IndyTCPClients selbst ?