Article View: borland.public.cppbuilder.internet.socket
Article #716Re: 'could not bind socket' error
From: Dennis Jones
Date: Tue, 20 Nov 2007 18:24
Date: Tue, 20 Nov 2007 18:24
48 lines
2268 bytes
2268 bytes
"Dennis Jones" <nospam@nospam.com> wrote in message
news:47431d9f$1@newsgroups.borland.com...
> Hello,
>
> I have an application which frequently fails to start with the message:
>
> "Could not bind socket. Address and port are already in use."
>
> This happens (for no apparent reason) often enough that it is time for me
> to start investigating it.
If it helps to see some code, here is the code that I use to start the
server:
void TMyServer::Start()
{
if ( !TCPServer->Active )
{
TCPServer->ThreadClass = __classid(TMyPeerThread);
TCPServer->OnExecute = TCPServerExecute;
TCPServer->OnConnect = TCPClientConnect;
TCPServer->OnDisconnect = TCPClientDisconnect;
TCPServer->DefaultPort = FPort;
// Set up the bindings:
TCPServer->Bindings->Clear();
TIdSocketHandle *NewBinding = TCPServer->Bindings->Add();
NewBinding->IP = FHostAddress;
AnsiString HostAddress( "All Adapters" );
if ( !FHostAddress.IsEmpty() )
{
HostAddress = FHostAddress;
}
LogMsg( AnsiString().sprintf( "Starting server on <%s:%d>",
HostAddress.c_str(), FPort ) );
TCPServer->Active = true;
LogMsg( AnsiString().sprintf( "Started server on <%s:%d>",
HostAddress.c_str(), FPort ) );
}
}
- Dennis
Technical Details
Message-ID:
<4743264f@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<47431d9f$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,128d041863311899 X-Google-Attributes: gid11508e,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit From: "Dennis Jones" <nospam@nospam.com> Newsgroups: borland.public.cppbuilder.internet.socket References: <47431d9f$1@newsgroups.borland.com> Subject: Re: 'could not bind socket' error Date: Tue, 20 Nov 2007 10:24:16 -0800 Lines: 50 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.3138 X-RFC2646: Format=Flowed; Response X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198 NNTP-Posting-Host: 71.245.109.58 Message-ID: <4743264f@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1195583055 71.245.109.58 (20 Nov 2007 10:24:15 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail