🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.internet.socket
Article #2916

Re: Unresolved external 'Idantifreeze::TIdAntiFreeze:

#2916
From: Liu Shan
Date: Wed, 11 Jan 2006 06:43
307 lines
9256 bytes
Here is code I converted from pascal to BCB6.

Once I click on "Start" button, I got "Error starting server", I click 
"Strat" button again, got "Access violation at address 40006834 in module 
'rtl60.bpl". read of address....." or after "Error starting server", I close 
application, also got acccess violation.


void __fastcall TfrmMain::FormCreate(TObject *Sender)
{
    fErrors =  new TStringList;
    PopulateIPAddresses();
}

void TfrmMain::PopulateIPAddresses()
{
    int i, port;
    TList *PortList;

    lbIPs->Clear();
    lbIPs->Items = GStack->LocalAddresses;
    lbIPs->Items->Add("127.0.0.1");

    try
    {
        cboPorts->Items->Add("RSBindingAny");
        cboPorts->Items->BeginUpdate();

        PortList = IdPorts();
        for (i=0; i< PortList->Count; i++)
        {
            port = reinterpret_cast<int>(PortList->Items[i]);

            cboPorts->Items->Add(PortDescription(port));
        }
    }
     __finally
    {
        cboPorts->Items->EndUpdate();
    }
}


AnsiString TfrmMain::PortDescription(int PortNumber)
{
    AnsiString Result;
    TStrings *tStr;
    Result = "";

    tStr = GStack->WSGetServByPort(PortNumber);
    if (tStr->Count > 0)
    {
        Result = AnsiString(PortNumber) + ": " + tStr->CommaText;
    }

    tStr->Free();

    return Result;
}

//---------------------------------------------------------------------------
bool TfrmMain::StopServer()
{
    bool Result;

    IdTCPServer->Active = false;
    IdTCPServer->Bindings->Clear();
    Result = !IdTCPServer->Active;
    fServerRunning = !Result;
    if (Result)
    {
        StatusBar->SimpleText = "Server stopped";
        lbProcesses->Items->Append("Server stopped");
    }
    else
    {
        StatusBar->SimpleText = "Server running";
        lbProcesses->Items->Append("Server not stopped");
    }

    return Result;
}

bool TfrmMain::StartServer()
{
    TIdSocketHandle *Binding;
    int i;
    TStringList *SL ;

    bool result;

    result = false;

    if (!StopServer())
    {
        fErrors->Append("Error stopping server");
        result = false;
        return result;
    }

    SL = new TStringList;
    if (!SL) return false;


    IdTCPServer->Active = false;
    IdTCPServer->Bindings->Clear();
    fServerRunning = false;

    try
    {
        for (i=0; i< lbIPs->Count; i++)
        {
            if( lbIPs->Checked[i] )
            {
                Binding = IdTCPServer->Bindings->Add();
                Binding->IP = lbIPs->Items->Strings[i];
                Binding->Port = StrToInt(edtPort->Text);  //default 2222
                SL->Append("Server bound to IP " + Binding->IP + " on port " 
+ edtPort->Text);
            }
        }

        if( IdTCPServer->Bindings->Count > 0 )
        {
            IdTCPServer->Active = true;
            fServerRunning = IdTCPServer->Active;  //here always return 
false
            lbProcesses->Items->AddStrings(SL);
        }


        if( fServerRunning )
        {
            lbProcesses->Items->Append("Server started");
            StatusBar->SimpleText = "Server running";
        }
        else
        {
            lbProcesses->Items->Append("Server stopped");
            StatusBar->SimpleText = "Server stopped";
        }

        result = fServerRunning;
    }
    catch (Exception &exception)
    {
        lbProcesses->Items->Append("Server not started");
        fErrors->Append(exception.Message);
        result = false;
        fServerRunning = result;
    }

    delete SL;

    return result;
}


void __fastcall TfrmMain::btnStartServerClick(TObject *Sender)
{
    int x,i;

    x = 0;
    for (i=0; i<lbIPs->Count; i++)
    {
        if (lbIPs->Checked[i])
            x++;
    }

    if (x < 1)
    {
        ShowMessage("Cannot proceed until you select at least one IP to 
bind!");
        return;
    }

    fErrors->Clear();
    if (!StartServer())
        ShowMessage("Error starting server\t\t" + fErrors->CommaText);
    else
        ShowMessage("Server started successfully!");
}
//---------------------------------------------------------------------------

void __fastcall TfrmMain::FormDestroy(TObject *Sender)
{
    if (fErrors)
        delete fErrors;
}
//---------------------------------------------------------------------------

void __fastcall TfrmMain::cboPortsChange(TObject *Sender)
{
    AnsiString strPort;
    int pos;
    strPort = cboPorts->Items->Strings[cboPorts->ItemIndex];

    pos = strPort.Pos(":");
    if (pos > 0)
    {
        edtPort->Text = strPort.SubString(1,pos-1);
    }
}
//---------------------------------------------------------------------------

void __fastcall TfrmMain::btnStopServerClick(TObject *Sender)
{
    fErrors->Clear();
    if (!fServerRunning)
    {
        ShowMessage("Server it not running - no need to stop !");
        return;
    }

    if (StopServer())

        ShowMessage("Error stopping server\t\t" + fErrors->CommaText);
    else
        ShowMessage("Server stopped successfully");

}
//---------------------------------------------------------------------------

void __fastcall TfrmMain::btnClearMessagesClick(TObject *Sender)
{
    lbProcesses->Clear();
}
//---------------------------------------------------------------------------

void __fastcall TfrmMain::IdTCPServerExecute(TIdPeerThread *AThread)
{
    AnsiString Command, tmpStr ;

    Command = AThread->Connection->ReadLn();
    Command = Command.UpperCase();
    if (Command.AnsiCompare("TIME") == 0)
    {
        tmpStr = FormatDateTime("hh:nn:ss",Now());
        AThread->Connection->WriteLn(tmpStr);
    }
    else if(Command.AnsiCompare("DATE") == 0)
    {
        tmpStr = FormatDateTime("dd/mmm/yyyy",Date());
        AThread->Connection->WriteLn(tmpStr);
    }
    else if(Command.AnsiCompare("TICKCOUNT") == 0)
    {
        AThread->Connection->WriteInteger(GetTickCount());
    }
    else if (Command.AnsiCompare("QUIT") == 0)
    {
        AThread->Connection->WriteLn("Goodbye!");
        AThread->Connection->Disconnect();
    }
    else
        AThread->Connection->WriteLn("Command not recognised - try again!");

}
//---------------------------------------------------------------------------

void __fastcall TfrmMain::IdTCPServerConnect(TIdPeerThread *AThread)
{
    AThread->Connection->WriteLn("Welcome to the Indy TCP basic 
client/server demo");
}
//---------------------------------------------------------------------------

void __fastcall TfrmMain::btnExitClick(TObject *Sender)
{
    Close();
}



"Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message 
news:43c496ed$1@newsgroups.borland.com...
>
> "Liu Shan" <liushan@ps-electronic.com> wrote in message
> news:43c47703$1@newsgroups.borland.com...
>
>> I've modified my code according to your suggestion to
>> void to ignores the activation. But the server still cannot
>> start, that means, call function below:
>> IdTCPServer->Active = true;
>> fServerRunning = IdTCPServer->Active;
>
> Then please show your latest code.  The code I keep giving you works fine
> for me, so you must not be copying it into your project correctly.
>
>> fServerRunning always get false no matter you assign
>> IdTCPServer->Active = true or not.
>> What's matter?
>
> The only way setting the Active property to true can fail is if you have
> provided invalid Binding values.  But if that occured, you should be 
> seeing
> socket exceptions being thrown.
>
>> sometimes I got Access Violation.
>
> Creating Bindings does not throw AVs.  Where EXACTLY do the AVs occur in
> your code?  Please provide more details.
>
>
> Gambit
>
> 
Technical Details
Message-ID: <43c4a871@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!news.moat.net!pln-e!lotsanews.com!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail
References: <43bcec76$1@newsgroups.borland.com> <43bd5f66$1@newsgroups.borland.com> <43bdcbd3$1@newsgroups.borland.com> <43bdd68e@newsgroups.borland.com> <43be37e8@newsgroups.borland.com> <43bebfd0$1@newsgroups.borland.com> <43c1be5a$1@newsgroups.borland.com> <43c23f02@newsgroups.borland.com> <43c47703$1@newsgroups.borland.com> <43c496ed$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,a9ad1d742dfc75bf
X-Google-Attributes: gid11508e,public
X-Google-Language: ENGLISH,ASCII-7-bit
Reply-To: "Liu Shan" <liushan@ps-electronic.com>
From: "Liu Shan" <liushan@ps-electronic.com>
Newsgroups: borland.public.cppbuilder.internet.socket
References: <43bcec76$1@newsgroups.borland.com> <43bd5f66$1@newsgroups.borland.com> <43bdcbd3$1@newsgroups.borland.com> <43bdd68e@newsgroups.borland.com> <43be37e8@newsgroups.borland.com> <43bebfd0$1@newsgroups.borland.com> <43c1be5a$1@newsgroups.borland.com> <43c23f02@newsgroups.borland.com> <43c47703$1@newsgroups.borland.com> <43c496ed$1@newsgroups.borland.com>
Subject: Re: Unresolved external 'Idantifreeze::TIdAntiFreeze:
Date: Wed, 11 Jan 2006 14:43:06 +0800
Lines: 309
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
X-RFC2646: Format=Flowed; Original
NNTP-Posting-Host: 219.74.19.168
Message-ID: <43c4a871@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1136961649 219.74.19.168 (10 Jan 2006 22:40:49 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!news.moat.net!pln-e!lotsanews.com!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail