🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: TCP

#2998
From: Remy Lebeau (TeamB)
Date: Fri, 09 Dec 2005 22:22
65 lines
2876 bytes
"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: <439a03e0$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>

Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,ae2c1a9c997cef31
X-Google-Attributes: gid11508e,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com>
Newsgroups: borland.public.cppbuilder.internet.socket
References: <4399dee8@newsgroups.borland.com>
Subject: Re: TCP
Date: Fri, 9 Dec 2005 14:22:12 -0800
Lines: 67
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
NNTP-Posting-Host: 68.69.17.41
Message-ID: <439a03e0$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1134167008 68.69.17.41 (9 Dec 2005 14:23:28 -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