I need to implement a TCP Server
connection with TIdTCPServer
component.
I already did it with GUI
(drag & drop) and its working. But I need to Split form and TCP
implementations. Example codes I've seen so far always uses TIdTCPServer
as the member of TForm
class.(result of drag and drop).
How I Call TCPConnection
class that I've implemented from the TForm
TCPConnection CConnection = new TCPConnection(Owner, this);
Here is how I try to create a TCP Server
Connection.
TCPConnection::TCPConnection(TComponent* Owner, TForm4* TSuperForm){
IdTCPServer1 = new TIdTCPServer(Owner);
IdTCPServer1->Bindings->Clear();
//IdTCPServer1->Bindings->Add()->SetBinding("10.10.2.103", 774);
IdTCPServer1->OnConnect = (TIdServerThreadEvent)(&OnConnect);
IdTCPServer1->OnExecute = (TIdServerThreadEvent)&OnExecute;
IdTCPServer1->OnDisconnect = (TIdServerThreadEvent)&OnConnect;
IdTCPServer1->OnException = (TIdServerThreadExceptionEvent)&OnException;
IdTCPServer1->DefaultPort = 774;
IdTCPServer1->Bindings->Add();
IdTCPServer1->Bindings->Items[0]->IP="10.10.2.103";
IdTCPServer1->Bindings->Items[0]->Port=774;
IdTCPServer1->ListenQueue = 15;
IdTCPServer1->MaxConnections = 15;
IdTCPServer1->TerminateWaitTime = 5000;
IdTCPServer1->Active = true;
this->TSuperForm = TSuperForm;
}
So far that codes work. But when I try to reach the context, connection is lost and throws
an exception
void TCPConnection::OnConnect(TIdContext *AContext){
String IP = AContext->Binding()->PeerIP;
}
void TCPConnection::OnException(TIdContext *AContext, Exception *AException)
{
ShowMessage("Error:" + AException->ToString());
}
Error
says TIdTaskThreadWork
(I'll edit error, might be wrong)
If I don't try to reach AContext, connection stays without problem.
Might be something about thread, locking list, ...
Any Suggestions?