Article View: borland.public.cppbuilder.internet.socket
Article #5554Re: Client Socket Connect Question
From: Remy Lebeau (TeamB)
Date: Wed, 04 Aug 2004 17:30
Date: Wed, 04 Aug 2004 17:30
78 lines
3226 bytes
3226 bytes
"OKusmen" <okusmen@aselsan.com.tr> wrote in message
news:41109cf1@newsgroups.borland.com...
> void TTCPSendDataModule::OpenConnection()
> {
> SendSocket->Host = TCPSendTable->FieldValues["HostName"];
> SendSocket->Port = TCPSendTable->FieldValues["PortNo"];
Where exactly are you getting the Host and Port values from? What are the
actual values themselves?
> try{
> SendSocket->Open();
> connectionWaiting = true;
> }catch(...){}
You should always catch VCL exceptions explitically, don't use '...':
catch(const Exception &){}
> if( SendSocket->Active &&
> SendSocket->Socket->SendBuf(buffer,bufferLength) == bufferLength ) //
packet
> is sent sucessfully
> result = true;
> }catch(...){}
FYI, just because SendBuf() may not take the full data at one time is not an
error. Only when it returns -1 or throws an exception is it an error. You
should be looping through the data until you have sent it all, ie:
bool TTCPSendDataModule::SendPacket(BYTE *buffer,int bufferLength)
{
if( SendSocket->Active )
{
try
{
while( bufferlength > 0 )
{
int sent = SendSocket->Socket->SendBuf(buffer,
bufferLength);
if( sent < 0 )
{
if( SendSocket->Active )
{
// send would block, try again...
Application->ProcessMessages();
continue;
}
// error sending and OnError already caught it...
return false;
}
if( sent == 0 )
{
// disconnected...
return false;
}
buffer += sent;
bufferlength -= sent;
}
// finished...
return true;
}
catch(const Exception &)
{
// error...
}
}
return false;
}
Gambit
Technical Details
Message-ID:
<41111ce5$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<410f4afe@newsgroups.borland.com> <410fbe48$1@newsgroups.borland.com> <41109cf1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,5e7c9fcee6f0909e X-Google-Attributes: gid11508e,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Remy Lebeau \(TeamB\)" <gambit47.no.spam@no.spam.yahoo.com> Newsgroups: borland.public.cppbuilder.internet.socket References: <410f4afe@newsgroups.borland.com> <410fbe48$1@newsgroups.borland.com> <41109cf1@newsgroups.borland.com> Subject: Re: Client Socket Connect Question Date: Wed, 4 Aug 2004 10:30:01 -0700 Lines: 80 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: <41111ce5$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1091640549 68.69.17.41 (4 Aug 2004 10:29:09 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail