BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

'Could not bind socket. Address and port are already in use

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Internet Winsock
View previous topic :: View next topic  
Author Message
Ernest P. Woorell
Guest





PostPosted: Mon May 21, 2007 9:54 pm    Post subject: 'Could not bind socket. Address and port are already in use Reply with quote



I have been working with this all morning. I have two clients on a test
form. I open each by it's own button. Most of the time I get the following
"Project SenderPrj.exe raised exception class EIdCouldNotBindSocket with
message 'Could not bind socket. Address and port are already in use.'. "

Sometimes I am able to open one of them but usually not.

Now here is the wierd part. After investigating the server, testing to
assure no other device is using the same port, I finally diconnected the
network cable from the server. I still get the same error!! Just to make
sure, I ping those ports after teh cable is disconnected and receive no
return.

How can the port be in use when the network cable is disconnected??

Thanks






procedure TForm1.btnConn6Click(Sender: TObject);
begin
try
IdTCPClient1.Connect;
except
on e: exception do SHowMessage(e.Message+' Send 6');
end;

end;

procedure TForm1.btnConn7Click(Sender: TObject);
begin
try
IdTCPClient2.Connect;
except
on e: exception do SHowMessage(e.Message +' Send 7');
end;
end;


object IdTCPClient1: TIdTCPClient
OnDisconnected = IdTCPClient1Disconnected
BoundIP = '192.168.100.13'
BoundPort = 23
ConnectTimeout = 0
Host = '192.168.100.13'
IPVersion = Id_IPv4
OnConnected = IdTCPClient1Connected
Port = 23
ReadTimeout = -1
OnBeforeBind = IdTCPClient1BeforeBind
Left = 168
Top = 152
end
object IdTCPClient2: TIdTCPClient
OnDisconnected = IdTCPClient2Disconnected
BoundIP = '192.168.100.55'
BoundPort = 23
ConnectTimeout = 0
Host = '192.168.100.55'
IPVersion = Id_IPv4
OnConnected = IdTCPClient2Connected
Port = 23
ReadTimeout = -1
OnBeforeBind = IdTCPClient2BeforeBind
Left = 288
Top = 152
end
Back to top
Ernest P. Woorell
Guest





PostPosted: Mon May 21, 2007 11:42 pm    Post subject: Re: 'Could not bind socket. Address and port are already in Reply with quote



Okay,
After loosing half a day I think I got it figured. I Set the bound port to
0 and cleared the bound IP.

I checked the help and still do not understand why these parameters must be
cleared. Since I have multiple network connections on my laptop, I assumed
these values were relevent.


"Ernest P. Woorell" <lkillen (AT) charter (DOT) net> wrote in message
news:4651ce6d$1 (AT) newsgroups (DOT) borland.com...
Quote:
I have been working with this all morning. I have two clients on a test
form. I open each by it's own button. Most of the time I get the
following "Project SenderPrj.exe raised exception class
EIdCouldNotBindSocket with message 'Could not bind socket. Address and
port are already in use.'. "

Sometimes I am able to open one of them but usually not.

Now here is the wierd part. After investigating the server, testing to
assure no other device is using the same port, I finally diconnected the
network cable from the server. I still get the same error!! Just to make
sure, I ping those ports after teh cable is disconnected and receive no
return.

How can the port be in use when the network cable is disconnected??

Thanks






procedure TForm1.btnConn6Click(Sender: TObject);
begin
try
IdTCPClient1.Connect;
except
on e: exception do SHowMessage(e.Message+' Send 6');
end;

end;

procedure TForm1.btnConn7Click(Sender: TObject);
begin
try
IdTCPClient2.Connect;
except
on e: exception do SHowMessage(e.Message +' Send 7');
end;
end;


object IdTCPClient1: TIdTCPClient
OnDisconnected = IdTCPClient1Disconnected
BoundIP = '192.168.100.13'
BoundPort = 23
ConnectTimeout = 0
Host = '192.168.100.13'
IPVersion = Id_IPv4
OnConnected = IdTCPClient1Connected
Port = 23
ReadTimeout = -1
OnBeforeBind = IdTCPClient1BeforeBind
Left = 168
Top = 152
end
object IdTCPClient2: TIdTCPClient
OnDisconnected = IdTCPClient2Disconnected
BoundIP = '192.168.100.55'
BoundPort = 23
ConnectTimeout = 0
Host = '192.168.100.55'
IPVersion = Id_IPv4
OnConnected = IdTCPClient2Connected
Port = 23
ReadTimeout = -1
OnBeforeBind = IdTCPClient2BeforeBind
Left = 288
Top = 152
end
Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Mon May 21, 2007 11:52 pm    Post subject: Re: 'Could not bind socket. Address and port are already in Reply with quote



"Ernest P. Woorell" <lkillen (AT) charter (DOT) net> wrote in message
news:4651ce6d$1 (AT) newsgroups (DOT) borland.com...

Quote:
I have been working with this all morning. I have two clients on
a test form. I open each by it's own button. Most of the time I
get the following "Project SenderPrj.exe raised exception class
EIdCouldNotBindSocket with message 'Could not bind socket.
Address and port are already in use.'. "

When a socket is closed, it is not fully closed right away. The OS
keeps it alive internally for an extra period of time in order to
catch any pending data on the network.

You said this error is happening on the client side. The only way you
could be getting this error on a client is if you are using the
BoundPort property. By default, it is set to 0, which tells the OS to
bind the socket to a random local port that is guaranteed to be
available for use. If the BoundPort is not 0, then the socket is
bound to that specific port each time. So if you disconnect and then
reopen the socket on the same local port within a short amount of
time, the port may very well not be ready for reuse just yet.

To get around that, you have to enable the SO_REUSEADDR flag on the
socket before it is bound. If you are using Indy 9 or earlier, it is
not possible to do that without changing Indy's source code, though.
But if you are using Indy 10, then TIdTCPClient has a ReuseSocket
property available that you can set to True.

Quote:
How can the port be in use when the network cable is disconnected??

This has nothing to do with the cable. The OS still has the resources
open for the old socket.


Gambit
Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Tue May 22, 2007 1:20 am    Post subject: Re: 'Could not bind socket. Address and port are already in Reply with quote

"Ernest P. Woorell" <lkillen (AT) charter (DOT) net> wrote in message
news:4651e7b5 (AT) newsgroups (DOT) borland.com...

Quote:
I checked the help and still do not understand why these
parameters must be cleared.

Under normal situations, you don't usually need to use them at all.
The main reason to ever use the BoundPort is if your client is behind
a firewall that blocks which outbound ports are available. You could
set the BoundPort to a port that is, or can be, opened up for your
application to use. Otherwise, it is best to leave the BoundPort to 0
so the OS can manage the port assignment for you.

As for the BoundIP, all that does is tells the OS which NIC card to
use for the connection. If not specified, then the OS picks the best
one based on which of the available routing tables are best suited for
the specified IP being connected to.

Quote:
Since I have multiple network connections on my laptop, I
assumed these values were relevent.

The BoundIP is, yes. The BoundPort is not related to that. Though
you can use the same port on different NICs without conflict,
obviously.


Gambit
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Internet Winsock All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.