Article View: borland.public.cppbuilder.internet.socket
Article #3005Re: TCP
From: Remy Lebeau (TeamB)
Date: Mon, 12 Dec 2005 17:42
Date: Mon, 12 Dec 2005 17:42
67 lines
2969 bytes
2969 bytes
"Jesper" <jesper@safholm.com> wrote in message
news:439b1a46$1@newsgroups.borland.com...
> Hmm, I can't make it work. I get the error:
> "Cannot assign requested address".
That should only happen if you are still using the BoundIP property, and
specifying an invalid local IP address, or are specifying a
BoundIP/BoundPort combination that is already in use elsewhere.
> void __fastcall TForm1::IdTCPClient1Connected(TObject *Sender)
> {
> IdTCPClient1->Host = Edit1->Text;
> IdTCPClient1->Port = Edit2->Text.ToIntDef(0);
Why are you changing the Host and Port in the OnConnected event? You should
not be doing that. Do that in the button OnClick event that is calling
Connect().
Also, why are you sending the file in the OnConnected event as well? Indy
is not an event-driven library. You should send the file in the same code
that is calling Connect(), ie:
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)
{
if( IdTCPClient1->Connected() )
IdTCPClient1->Disconnect();
IdTCPClient1->Host = Edit1->Text;
IdTCPClient1->Port = Edit2->Text.ToIntDef(0);
IdTCPClient1->Connect();
TFileStream *FStream = new TFileStream("test\\test.txt", fmOpenRead
| fmShareDenyWrite);
try
{
IdTCPClient1->WriteStream(FStream, true, true, 0);
}
__finally {
delete FStream;
}
//...
}
Gambit
Technical Details
Message-ID:
<439db6ba$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!203.109.252.33.MISMATCH!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<4399dee8@newsgroups.borland.com> <439a03e0$1@newsgroups.borland.com> <439b1a46$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 From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> Newsgroups: borland.public.cppbuilder.internet.socket References: <4399dee8@newsgroups.borland.com> <439a03e0$1@newsgroups.borland.com> <439b1a46$1@newsgroups.borland.com> Subject: Re: TCP Date: Mon, 12 Dec 2005 09:42:21 -0800 Lines: 69 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: <439db6ba$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1134409402 68.69.17.41 (12 Dec 2005 09:43:22 -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!203.109.252.33.MISMATCH!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail