473,320 Members | 1,876 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to "kill" a tcp port...

I'm building a relatively simple client-server app. One of the functions of
the client is to notify the server when it terminates, this all works fine.
The problem comes in when the server is stopped before the client, in which
case the client "hangs", waiting to talk to the server.

This is how it works:
Server: Starts listening on a tcp port, say 3000 (by registering a
TcpServerChannel and invoking RegisterWellKnownServiceType).
When I shutdown the server, I call the
RemotingServices.Disconnect for the object, then I call StopListening for
the TcpServerChannel and then I call ChannelServices.UnregisterChannel.
Client: When it shutsdown, it gets a reference to the server objecct by
using Activator.GetOjbect and then calls a Notify method. If the server is
still running, the Notify works fine, however, if the server is not running,
the client just "hangs" on the method call (when I debug it using VS, it
never returns from the Notify call and I have to kill the process).

When I do a netstat, it shows that the port the server was listening on is
still in the "LISTENING"-status.

Is there any way of forcefully killing or closing this port?

Any help would really be appreciated!
Thanks
Nov 16 '05 #1
10 5847
Thread it and terminate thread if call is taking too long.

Rob.

"Jako Menkveld" <ja***********@envalue.ch> wrote in message
news:uk**************@TK2MSFTNGP15.phx.gbl...
I'm building a relatively simple client-server app. One of the functions
of
the client is to notify the server when it terminates, this all works
fine.
The problem comes in when the server is stopped before the client, in
which
case the client "hangs", waiting to talk to the server.

This is how it works:
Server: Starts listening on a tcp port, say 3000 (by registering a
TcpServerChannel and invoking RegisterWellKnownServiceType).
When I shutdown the server, I call the
RemotingServices.Disconnect for the object, then I call StopListening for
the TcpServerChannel and then I call ChannelServices.UnregisterChannel.
Client: When it shutsdown, it gets a reference to the server objecct
by
using Activator.GetOjbect and then calls a Notify method. If the server
is
still running, the Notify works fine, however, if the server is not
running,
the client just "hangs" on the method call (when I debug it using VS, it
never returns from the Notify call and I have to kill the process).

When I do a netstat, it shows that the port the server was listening on is
still in the "LISTENING"-status.

Is there any way of forcefully killing or closing this port?

Any help would really be appreciated!
Thanks

Nov 16 '05 #2
Rob

I'll give that a try. Are you saying there is no way of closing the socket
from the Server side then?

Thanks
Jako

"Rob R. Ainscough" <ro*****@pacbell.net> wrote in message
news:eL**************@TK2MSFTNGP15.phx.gbl...
Thread it and terminate thread if call is taking too long.

Rob.

"Jako Menkveld" <ja***********@envalue.ch> wrote in message
news:uk**************@TK2MSFTNGP15.phx.gbl...
I'm building a relatively simple client-server app. One of the functions
of
the client is to notify the server when it terminates, this all works
fine.
The problem comes in when the server is stopped before the client, in
which
case the client "hangs", waiting to talk to the server.

This is how it works:
Server: Starts listening on a tcp port, say 3000 (by registering a
TcpServerChannel and invoking RegisterWellKnownServiceType).
When I shutdown the server, I call the
RemotingServices.Disconnect for the object, then I call StopListening for
the TcpServerChannel and then I call ChannelServices.UnregisterChannel.
Client: When it shutsdown, it gets a reference to the server objecct
by
using Activator.GetOjbect and then calls a Notify method. If the server
is
still running, the Notify works fine, however, if the server is not
running,
the client just "hangs" on the method call (when I debug it using VS, it
never returns from the Notify call and I have to kill the process).

When I do a netstat, it shows that the port the server was listening on
is
still in the "LISTENING"-status.

Is there any way of forcefully killing or closing this port?

Any help would really be appreciated!
Thanks


Nov 16 '05 #3
Jako Menkveld wrote:
Rob

I'll give that a try. Are you saying there is no way of closing the socket from the Server side then?


1.If the server process (not appdomain) dies without closing the port,
the OS will kill it.

2.TCP itself should give the client an error if the server dies without
closing the connection. Maybe it is ignored by .NET remoting?

What I don't understand is that your netstat shows the port was still
listening after server quit.. Did the server process really quit?

Nov 16 '05 #4
"Aquila Deus" <aq*********@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Jako Menkveld wrote:
Rob

I'll give that a try. Are you saying there is no way of closing the socket
from the Server side then?


1.If the server process (not appdomain) dies without closing the port,
the OS will kill it.


I also thought this would be the case, but for some reason the OS (Win XP by
the way), keeps the connection open because the client-side was still
connected. It doesn't make a lot of sense, but that's what seems to happen.

2.TCP itself should give the client an error if the server dies without
closing the connection. Maybe it is ignored by .NET remoting?
I can really comment on that, once again, I would have expected something
like that to happen, but no luck there either.

What I don't understand is that your netstat shows the port was still
listening after server quit.. Did the server process really quit?


The server process did die (can't see it in Task Manager for any user). The
interesting thing is that if I run netstat -o and get the process ID of the
listener, I can't find that process ID in Task Manager either and it is
different from the original server's process ID.
Nov 16 '05 #5
Jako Menkveld wrote:
"Aquila Deus" <aq*********@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Jako Menkveld wrote:
Rob

I'll give that a try. Are you saying there is no way of closing
the socket
from the Server side then?
1.If the server process (not appdomain) dies without closing the port, the OS will kill it.


I also thought this would be the case, but for some reason the OS

(Win XP by the way), keeps the connection open because the client-side was still connected. It doesn't make a lot of sense, but that's what seems to happen.

2.TCP itself should give the client an error if the server dies without closing the connection. Maybe it is ignored by .NET remoting?
I can really comment on that, once again, I would have expected

something like that to happen, but no luck there either.

What I don't understand is that your netstat shows the port was still listening after server quit.. Did the server process really quit?

The server process did die (can't see it in Task Manager for any

user). The interesting thing is that if I run netstat -o and get the process ID of the listener, I can't find that process ID in Task Manager either and it is different from the original server's process ID.


And what's the name of the new process that took the port? Maybe
windows needs to launch another program to kill unclosed port (just
like how it kills apps forcefully)

Nov 16 '05 #6
"Aquila Deus" <aq*********@gmail.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
Jako Menkveld wrote:
"Aquila Deus" <aq*********@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
> Jako Menkveld wrote:
>> Rob
>>
>> I'll give that a try. Are you saying there is no way of closing the > socket
>> from the Server side then?
>
> 1.If the server process (not appdomain) dies without closing the port, > the OS will kill it.


I also thought this would be the case, but for some reason the OS

(Win XP by
the way), keeps the connection open because the client-side was still

connected. It doesn't make a lot of sense, but that's what seems to

happen.
>
> 2.TCP itself should give the client an error if the server dies without > closing the connection. Maybe it is ignored by .NET remoting?


I can really comment on that, once again, I would have expected

something
like that to happen, but no luck there either.
>
> What I don't understand is that your netstat shows the port was still > listening after server quit.. Did the server process really quit?
>


The server process did die (can't see it in Task Manager for any

user). The
interesting thing is that if I run netstat -o and get the process ID

of the
listener, I can't find that process ID in Task Manager either and it

is
different from the original server's process ID.


And what's the name of the new process that took the port? Maybe
windows needs to launch another program to kill unclosed port (just
like how it kills apps forcefully)


I'm not sure what the name is, but it seems like Windows launches another
process to keep the port open, rather than kill it.
Nov 16 '05 #7
Jako Menkveld wrote:
"Aquila Deus" <aq*********@gmail.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
Jako Menkveld wrote:
"Aquila Deus" <aq*********@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
> Jako Menkveld wrote:
>> Rob
>>
>> I'll give that a try. Are you saying there is no way of closing
the
> socket
>> from the Server side then?
>
> 1.If the server process (not appdomain) dies without closing the port,
> the OS will kill it.

I also thought this would be the case, but for some reason the OS

(Win XP by
the way), keeps the connection open because the client-side was
still
connected. It doesn't make a lot of sense, but that's what seems
to happen.

>
> 2.TCP itself should give the client an error if the server dies

without
> closing the connection. Maybe it is ignored by .NET remoting?

I can really comment on that, once again, I would have expected

something
like that to happen, but no luck there either.

>
> What I don't understand is that your netstat shows the port was

still
> listening after server quit.. Did the server process really
quit? >

The server process did die (can't see it in Task Manager for any

user). The
interesting thing is that if I run netstat -o and get the process

ID of the
listener, I can't find that process ID in Task Manager either and
it is
different from the original server's process ID.


And what's the name of the new process that took the port? Maybe
windows needs to launch another program to kill unclosed port (just
like how it kills apps forcefully)


I'm not sure what the name is, but it seems like Windows launches

another process to keep the port open, rather than kill it.


Uhh.. it may takes a while for the new process to kill the port... Can
you re-produce it?

Nov 16 '05 #8
"Aquila Deus" <aq*********@gmail.com> wrote in message
news:11**********************@c13g2000cwb.googlegr oups.com...
Jako Menkveld wrote:
"Aquila Deus" <aq*********@gmail.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
> Jako Menkveld wrote:
>> "Aquila Deus" <aq*********@gmail.com> wrote in message
>> news:11**********************@g14g2000cwa.googlegr oups.com...
>> > Jako Menkveld wrote:
>> >> Rob
>> >>
>> >> I'll give that a try. Are you saying there is no way of closing > the
>> > socket
>> >> from the Server side then?
>> >
>> > 1.If the server process (not appdomain) dies without closing the
> port,
>> > the OS will kill it.
>>
>> I also thought this would be the case, but for some reason the OS
> (Win XP by
>> the way), keeps the connection open because the client-side was still >
>> connected. It doesn't make a lot of sense, but that's what seems to > happen.
>>
>> >
>> > 2.TCP itself should give the client an error if the server dies
> without
>> > closing the connection. Maybe it is ignored by .NET remoting?
>>
>> I can really comment on that, once again, I would have expected
> something
>> like that to happen, but no luck there either.
>>
>> >
>> > What I don't understand is that your netstat shows the port was
> still
>> > listening after server quit.. Did the server process really quit? >> >
>>
>> The server process did die (can't see it in Task Manager for any
> user). The
>> interesting thing is that if I run netstat -o and get the process ID > of the
>> listener, I can't find that process ID in Task Manager either and it > is
>> different from the original server's process ID.
>
> And what's the name of the new process that took the port? Maybe
> windows needs to launch another program to kill unclosed port (just
> like how it kills apps forcefully)
>


I'm not sure what the name is, but it seems like Windows launches

another
process to keep the port open, rather than kill it.


Uhh.. it may takes a while for the new process to kill the port... Can
you re-produce it?


Not right now, but I should be able to do that again. Is there something I
need to look out for and let you know what happened?
Nov 16 '05 #9

"Jako Menkveld" <ja***********@envalue.ch> wrote in message
news:uM*************@TK2MSFTNGP15.phx.gbl...
"Aquila Deus" <aq*********@gmail.com> wrote in message
news:11**********************@c13g2000cwb.googlegr oups.com...
Jako Menkveld wrote:
"Aquila Deus" <aq*********@gmail.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
> Jako Menkveld wrote:
>> "Aquila Deus" <aq*********@gmail.com> wrote in message
>> news:11**********************@g14g2000cwa.googlegr oups.com...
>> > Jako Menkveld wrote:
>> >> Rob
>> >>
>> >> I'll give that a try. Are you saying there is no way of

closing
> the
>> > socket
>> >> from the Server side then?
>> >
>> > 1.If the server process (not appdomain) dies without closing the
> port,
>> > the OS will kill it.
>>
>> I also thought this would be the case, but for some reason the OS
> (Win XP by
>> the way), keeps the connection open because the client-side was

still
>
>> connected. It doesn't make a lot of sense, but that's what seems

to
> happen.
>>
>> >
>> > 2.TCP itself should give the client an error if the server dies
> without
>> > closing the connection. Maybe it is ignored by .NET remoting?
>>
>> I can really comment on that, once again, I would have expected
> something
>> like that to happen, but no luck there either.
>>
>> >
>> > What I don't understand is that your netstat shows the port was
> still
>> > listening after server quit.. Did the server process really

quit?
>> >
>>
>> The server process did die (can't see it in Task Manager for any
> user). The
>> interesting thing is that if I run netstat -o and get the process

ID
> of the
>> listener, I can't find that process ID in Task Manager either and

it
> is
>> different from the original server's process ID.
>
> And what's the name of the new process that took the port? Maybe
> windows needs to launch another program to kill unclosed port (just
> like how it kills apps forcefully)
>

I'm not sure what the name is, but it seems like Windows launches

another
process to keep the port open, rather than kill it.


Uhh.. it may takes a while for the new process to kill the port... Can
you re-produce it?


Not right now, but I should be able to do that again. Is there something
I need to look out for and let you know what happened?

I reproduced it and ran a more detailed netstat.

The process ID is still one I can't find in Task Manager and the executable
responsible for the open port is displayed as "[System]". The components
involved in creating the connection is displayed as "-- unknown
component(s) --". Most of the other connections in the netstat list shows
actual executable and component names.

Does this help at all?
Nov 16 '05 #10
Jako Menkveld wrote:
"Jako Menkveld" <ja***********@envalue.ch> wrote in message
news:uM*************@TK2MSFTNGP15.phx.gbl...
"Aquila Deus" <aq*********@gmail.com> wrote in message
news:11**********************@c13g2000cwb.googlegr oups.com...
Jako Menkveld wrote:
"Aquila Deus" <aq*********@gmail.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
> Jako Menkveld wrote:
>> "Aquila Deus" <aq*********@gmail.com> wrote in message
>> news:11**********************@g14g2000cwa.googlegr oups.com...
>> > Jako Menkveld wrote:
>> >> Rob
>> >>
>> >> I'll give that a try. Are you saying there is no way of
closing
> the
>> > socket
>> >> from the Server side then?
>> >
>> > 1.If the server process (not appdomain) dies without closing the > port,
>> > the OS will kill it.
>>
>> I also thought this would be the case, but for some reason the OS > (Win XP by
>> the way), keeps the connection open because the client-side was still
>
>> connected. It doesn't make a lot of sense, but that's what seems to
> happen.
>>
>> >
>> > 2.TCP itself should give the client an error if the server dies > without
>> > closing the connection. Maybe it is ignored by .NET remoting? >>
>> I can really comment on that, once again, I would have expected > something
>> like that to happen, but no luck there either.
>>
>> >
>> > What I don't understand is that your netstat shows the port was > still
>> > listening after server quit.. Did the server process really
quit?
>> >
>>
>> The server process did die (can't see it in Task Manager for any > user). The
>> interesting thing is that if I run netstat -o and get the process ID
> of the
>> listener, I can't find that process ID in Task Manager either and it
> is
>> different from the original server's process ID.
>
> And what's the name of the new process that took the port? Maybe > windows needs to launch another program to kill unclosed port (just > like how it kills apps forcefully)
>

I'm not sure what the name is, but it seems like Windows launches
another
process to keep the port open, rather than kill it.

Uhh.. it may takes a while for the new process to kill the port... Can you re-produce it?

Not right now, but I should be able to do that again. Is there something I need to look out for and let you know what happened?

I reproduced it and ran a more detailed netstat.

The process ID is still one I can't find in Task Manager and the

executable responsible for the open port is displayed as "[System]". The components involved in creating the connection is displayed as "-- unknown
component(s) --". Most of the other connections in the netstat list shows actual executable and component names.

Does this help at all?


Yep, that means the OS has taken the unclosed port, and we have better
to stop here. Now it's time to track the client-side. Maybe you should
also report it as a bug to M$ (i dunno where to do so though).

Nov 16 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Fred | last post by:
There is a setting in INIT.ORA that has the unintended side-effect of making sure the ALTER SYSTEM KILL SESSION command has immediate affect. Without this setting, I've seen some instances where...
10
by: Jako Menkveld | last post by:
I'm building a relatively simple client-server app. One of the functions of the client is to notify the server when it terminates, this all works fine. The problem comes in when the server is...
1
by: =?Utf-8?B?QWxoYW1icmEgRWlkb3MgS2lxdWVuZXQ=?= | last post by:
Hi misters, Is it possible "kill" the thread of Backgroundworker ? In my Dowork event, I have NOT While for do e.Cancel = true, only have a call to external COM. If I want cancel, calling...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.