🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: TCP

#3001
From: Jesper
Date: Sat, 10 Dec 2005 18:12
129 lines
4496 bytes
Hmm, I can't make it work. I get the error: "Cannot assign requested 
address".
Here's my code:

void __fastcall TForm1::IdTCPClient1Connected(TObject *Sender)
{
IdTCPClient1->Host = Edit1->Text;
IdTCPClient1->Port = Edit2->Text.ToIntDef(0);
TFileStream *FStream = new TFileStream("test\\test.txt", fmOpenRead |
fmShareDenyWrite);
    try
    {
        IdTCPClient1->WriteStream(FStream, true, true);
    }
    __finally {
        delete FStream;
    }


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

void __fastcall TForm1::IdTCPServer1Connect(TIdPeerThread *AThread)
{
AnsiString FileName = "bhabhabh.txt";
        TFileStream *FStream = new TFileStream(FileName, fmCreate);
        try
        {
            try
            {
                AThread->Connection->ReadStream(FStream, -1, false);
            }
            __finally
            {
                delete FStream;
            }
        }
        catch(const Exception &)
        {
            DeleteFile(FileName);
        }
    }

//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
IdTCPClient1->Connect();
}







"Remy Lebeau (TeamB)" <no.spam@no.spam.com> skrev i meddelandet 
news:439a03e0$1@newsgroups.borland.com...
>
> "Jesper" <jesper@safholm.com> wrote in message
> news:4399dee8@newsgroups.borland.com...
>
>> IdTCPClient1->BoundIP = Edit1->Text; //The IP of the other computer
>
> That is not correct.  The BoundIP property is used to specify the IP of 
> the
> *local* machine that the socket will bind to.  Use the Host property 
> instead
> to specify the IP of the *remote* machine that the server is running on.
>
>> IdTCPClient1->WriteFile("test\\test.txt");
>
> I would not suggest using WriteFile() in this situation.  It does not
> provide any means of telling the other party how much data is actually 
> being
> sent.  I would suggest using WriteStream() instead, ie:
>
>    TFileStream *FStream = new TFileStream("test\\test.txt", fmOpenRead |
> fmShareDenyWrite);
>    try
>    {
>        IdTCPClient.WriteStream(FStream, true, true, 0);
>    }
>    __finally {
>        delete FStream;
>    }
>
> Then you can use ReadStream() on the TIdTCPServer to receive the data.
> ReadStream() can read the stream size ahead of time in order to optimize 
> the
> reading:
>
>    void __fastcall TForm1::IdTCPServer1Connect(TIdPeerThread *AThread)
>    {
>        AnsiString FileName = "some file name here";
>        TFileStream *FStream = new TFileStream(FileName, fmCreate);
>        try
>        {
>            try
>            {
>                AThread->Connection->ReadStream(FStream, -1, false);
>            }
>            __finally
>            {
>                delete FStream;
>            }
>        }
>        catch(const Exception &)
>        {
>            DeleteFile(FileName);
>        }
>    }
>
>> if(IdTCPClient1->Connected() == true)
>
> Why are you checking that after calling WriteFile() instead of after 
> calling
> Connect()?
>
> In any case, you don't need to check it at all anyway since Connect() will
> throw an exception if it fails.
>
>> My problem is IdTCPClient1->WriteFile.
>
> What is your actual problem with it?  Please be more specific.
>
>
> Gambit
>
> 
Technical Details
Message-ID: <439b1a46$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx01.iad01.newshosting.com!newshosting.com!news-out.newsfeeds.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail
References: <4399dee8@newsgroups.borland.com> <439a03e0$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,ae2c1a9c997cef31
X-Google-Attributes: gid11508e,public
X-Google-Language: ENGLISH,ASCII-7-bit
Reply-To: "Jesper" <jesper@safholm.com>
From: "Jesper" <jesper@safholm.com>
Newsgroups: borland.public.cppbuilder.internet.socket
References: <4399dee8@newsgroups.borland.com> <439a03e0$1@newsgroups.borland.com>
Subject: Re: TCP
Date: Sat, 10 Dec 2005 19:12:27 +0100
Lines: 131
Organization: Blackhole Productions
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: 213.164.198.226
Message-ID: <439b1a46$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1134238278 213.164.198.226 (10 Dec 2005 10:11:18 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx01.iad01.newshosting.com!newshosting.com!news-out.newsfeeds.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail