Board index » delphi » TCP CLIENT + REUSE LOCAL PORT + TIME_WAIT

TCP CLIENT + REUSE LOCAL PORT + TIME_WAIT


2004-06-07 07:21:38 PM
delphi68
Hi all.
May be this problem is somethere in the news but I have not find it, so
sorry if repeated.
I need a TCP client that needs to connect to a server (ip + port), no
problem at this point. But the problem comes because it is absolutely
neccesary for me to use always the same local port in the client side. The
problem comes when I close the socket and try to open it again, I have the
10048 error (socket still open in PC) during 4 minutes. Really it is an
operating system issue, that mantains the socket opened in the TIME_WAIT
state during 4 minutes.
My question is...can I configure this time so I can configure to n seconds
(even 0 seconds)? (not in the registry). I have been looking at the
setsockopts function, linger option..., but no results :-(
Any help would be appreciated. Thank you in advance and regards,
David Alcelay
Software ingenieer.
ULMA Handling Systems
 
 

Re:TCP CLIENT + REUSE LOCAL PORT + TIME_WAIT

"David" <XXXX@XXXXX.COM>writes
Quote
Hi all.
May be this problem is somethere in the news but I have not find it, so
sorry if repeated.
I need a TCP client that needs to connect to a server (ip + port), no
problem at this point. But the problem comes because it is absolutely
neccesary for me to use always the same local port in the client side. The
problem comes when I close the socket and try to open it again, I have the
10048 error (socket still open in PC) during 4 minutes. Really it is an
operating system issue, that mantains the socket opened in the TIME_WAIT
state during 4 minutes.
My question is...can I configure this time so I can configure to n seconds
(even 0 seconds)? (not in the registry). I have been looking at the
setsockopts function, linger option..., but no results :-(
Any help would be appreciated. Thank you in advance and regards,
David Alcelay
Software ingenieer.
ULMA Handling Systems

Why does your client need to use the same local port. Sounds like a bad
design. Sockets stay in the TIME_WAIT state for a reason.
Dan
 

Re:TCP CLIENT + REUSE LOCAL PORT + TIME_WAIT

"Dan F" <XXXX@XXXXX.COM>escribi?en el mensaje
Quote
"David" <XXXX@XXXXX.COM>writes
news:XXXX@XXXXX.COM...
>Hi all.
>May be this problem is somethere in the news but I have not find it, so
>sorry if repeated.
>I need a TCP client that needs to connect to a server (ip + port), no
>problem at this point. But the problem comes because it is absolutely
>neccesary for me to use always the same local port in the client side.
The
>problem comes when I close the socket and try to open it again, I have
the
>10048 error (socket still open in PC) during 4 minutes. Really it is an
>operating system issue, that mantains the socket opened in the TIME_WAIT
>state during 4 minutes.
>My question is...can I configure this time so I can configure to n
seconds
>(even 0 seconds)? (not in the registry). I have been looking at the
>setsockopts function, linger option..., but no results :-(
>Any help would be appreciated. Thank you in advance and regards,
>David Alcelay
>Software ingenieer.
>ULMA Handling Systems
>

Why does your client need to use the same local port. Sounds like a bad
design. Sockets stay in the TIME_WAIT state for a reason.

Dan


Jajajaja, yes, I knew someone would make that question. ;-D
I have to 'talk' with a Siemens PLC with a RFC1006 protocol (ISO-TCP), and
the Siemens PLC programmer says that even being a TCP Client/Server, he must
configure his local and remote port. We have done tests and I have tested
that I only can communicate if I configure my local port fixed as he has
configured it in his remote port.
This is also a problem for me, but it is the only way we can communicate (as
far as we know for the moment). I think there must be a better way but even
Siemens people (here in Spain) don't give us a solution at this moment.
I know that sockets stay in that state, but I think there must be a way to
do this.
Dan
 

Re:TCP CLIENT + REUSE LOCAL PORT + TIME_WAIT

"David" <XXXX@XXXXX.COM>writes
Quote

Jajajaja, yes, I knew someone would make that question. ;-D
I have to 'talk' with a Siemens PLC with a RFC1006 protocol (ISO-TCP), and
the Siemens PLC programmer says that even being a TCP Client/Server, he
must
configure his local and remote port. We have done tests and I have tested
that I only can communicate if I configure my local port fixed as he has
configured it in his remote port.
This is also a problem for me, but it is the only way we can communicate
(as
far as we know for the moment). I think there must be a better way but
even
Siemens people (here in Spain) don't give us a solution at this moment.
I know that sockets stay in that state, but I think there must be a way to
do this.
Dan

Ok, sounds like you have a genuine reason :)
Google turns this up:
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\tcpip\Parameters\TcpTim
edWaitDelay
If it isn't there, create it as a DWord. This is the time of the TIME_WAIT
state in seconds. And as with most things in Windows, it requires a restart
to take effect.
Dan
 

Re:TCP CLIENT + REUSE LOCAL PORT + TIME_WAIT

"Dan F" <XXXX@XXXXX.COM>escribi?en el mensaje
Quote

"David" <XXXX@XXXXX.COM>writes
news:XXXX@XXXXX.COM...
>
>Jajajaja, yes, I knew someone would make that question. ;-D
>I have to 'talk' with a Siemens PLC with a RFC1006 protocol (ISO-TCP),
and
>the Siemens PLC programmer says that even being a TCP Client/Server, he
must
>configure his local and remote port. We have done tests and I have
tested
>that I only can communicate if I configure my local port fixed as he has
>configured it in his remote port.
>This is also a problem for me, but it is the only way we can communicate
(as
>far as we know for the moment). I think there must be a better way but
even
>Siemens people (here in Spain) don't give us a solution at this moment.
>I know that sockets stay in that state, but I think there must be a way
to
>do this.
>Dan
>

Ok, sounds like you have a genuine reason :)

Google turns this up:


HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\tcpip\Parameters\TcpTim
edWaitDelay

If it isn't there, create it as a DWord. This is the time of the
TIME_WAIT
state in seconds. And as with most things in Windows, it requires a
restart
to take effect.

Dan


Hi Dan, thank you Dan for your help :-D
I was looking for that key in the registry.
As you see I have not any chance....so I have to train boxing this way ;-(
This change in the registry probably has effect in many other programs and
if possible I don't want to change the registry (if there is not another
solution then ok).
Is it possible to change the configuration of a lonely socket so it works
with that value changed? That is really my question...
David
 

Re:TCP CLIENT + REUSE LOCAL PORT + TIME_WAIT

"David" <XXXX@XXXXX.COM>escribi?en el mensaje
Quote

"Dan F" <XXXX@XXXXX.COM>escribi?en el mensaje
news:XXXX@XXXXX.COM...
>
>"David" <XXXX@XXXXX.COM>writes
>news:XXXX@XXXXX.COM...
>>
>>Jajajaja, yes, I knew someone would make that question. ;-D
>>I have to 'talk' with a Siemens PLC with a RFC1006 protocol (ISO-TCP),
and
>>the Siemens PLC programmer says that even being a TCP Client/Server,
he
>must
>>configure his local and remote port. We have done tests and I have
tested
>>that I only can communicate if I configure my local port fixed as he
has
>>configured it in his remote port.
>>This is also a problem for me, but it is the only way we can
communicate
>(as
>>far as we know for the moment). I think there must be a better way but
>even
>>Siemens people (here in Spain) don't give us a solution at this
moment.
>>I know that sockets stay in that state, but I think there must be a
way
to
>>do this.
>>Dan
>>
>
>Ok, sounds like you have a genuine reason :)
>
>Google turns this up:
>
>

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\tcpip\Parameters\TcpTim
>edWaitDelay
>
>If it isn't there, create it as a DWord. This is the time of the
TIME_WAIT
>state in seconds. And as with most things in Windows, it requires a
restart
>to take effect.
>
>Dan
>
>

Hi Dan, thank you Dan for your help :-D
I was looking for that key in the registry.
As you see I have not any chance....so I have to train boxing this way
;-(
This change in the registry probably has effect in many other programs and
if possible I don't want to change the registry (if there is not another
solution then ok).
Is it possible to change the configuration of a lonely socket so it works
with that value changed? That is really my question...
David


oopppsss...I forgot one thing:
Is it possible to change the configuration of a lonely socket so it works
with that value changed, or the possibility to reuse the port? That is
really my question...
David
 

Re:TCP CLIENT + REUSE LOCAL PORT + TIME_WAIT

David writes:
Quote

oopppsss...I forgot one thing:
Is it possible to change the configuration of a lonely socket so it works
with that value changed, or the possibility to reuse the port? That is
really my question...
I think so. I do just that on Linux, and I have a feeling this should work under Windows too.
As you create the socket to listen for incomming connection, just before you issue "bind" call, you must issue "setsockopt" with "SOL_SOCKET\SO_REUSEADDR" this should instruct OS that you wish to ignore the error, and you should be able to actualy have two different sockets listening on the same port (not that that would do you much good <g>) ...
Alex