|
우선..하나부터 열까지 일일이 질문드려서 정말 죄송;;
혼자 해보려고 이것저것 해봐두 잘 안되네요 ㅠㅠ
팁앤트릭에서 IP 알아내기 참고해서 다음과 같이 작성했구요..
일단 서버-클라이언트 통신은 잘 되었네요..
질문1) TCPServer->Bindings->Items[i]->PeerIP는
서버에 접속된 클라이언트들의 IP를 자동으로 수집하는 건가요?
아니면 TCPServer->Bindings 에 사용자가 설정해 놓은 값을 나타내는 건가요?
(테스트 해보니 통신이 잘 이루어지는 상태에서도 PeerIP는 NULL 이었어요.. 로컬 IP는 0.0.0.0 이었구요..
참.. GStack->LocalAddresses->Strings[0] 에서 로컬 IP는 잘 들어왔어요)
질문2) PeerIP를 자동으로 수집할려면 어떻게 해야 하나요?
아래 코드에 문제가 있는것 같네요..
질문3) TCPServer OnExecute()에서는 생성된 AThread 가지구 PeerIP 알 수 있는 방법이 있나요?
(음.. 2번과 약간 중복될 수도 있네요..)
그럼... 이 답답함을 해결해 주시리라 믿으며.. 꾸벅 __)
//---------------------------------------------------------------------------
void __fastcall TForm1::SendToClient()
{
//send data
char sBuf[BUF_SIZE];
sprintf(sBuf, "Server -> Client Test Message!");
TThreadList* thdlist = TCPServer->Threads;
TList* list = thdlist->LockList();
if(list->List==NULL) {thdlist->UnlockList(); return;}
TIdPeerThread* thd;
TIdTCPServerConnection* con;
RichEdit2->Clear();
try
{
for(int i = 0; i < list->Count; i++){
thd = (TIdPeerThread*)list->Items[i];
con = thd->Connection;
con->WriteBuffer(sBuf, BUF_SIZE); //write
// Edit1->Text = GStack->LocalAddresses->Strings[0];
AnsiString localIP, remoteIP;
localIP = TCPServer->Bindings->Items[i]->IP; //local IP
remoteIP = TCPServer->Bindings->Items[i]->PeerIP; // remote IP
RichEdit2->Lines->Add("localIP = " + localIP);
RichEdit2->Lines->Add("remoteIP = " + remoteIP);
}
}
__finally
{
thdlist->UnlockList();
}
}
//---------------------------------------------------------------------------
|