如何“杀死”一个tcp端口...... [英] How to "kill" a tcp port...

查看:286
本文介绍了如何“杀死”一个tcp端口......的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个相对简单的客户端 - 服务器应用程序。客户端的一个功能是在终止时通知服务器,这一切都正常。

服务器在客户端停止之前出现问题,其中

case客户端挂起,等待与服务器通话。


这是它的工作原理:

服务器:开始监听tcp端口,比如3000(通过注册一个
TcpServerChannel并调用RegisterWellKnownServiceType)。

当我关闭服务器时,我打电话给

RemotingServices.Disconnect为对象,然后我调用StopListening为

TcpServerChannel然后我调用ChannelServices.UnregisterChannel。

客户端:当它关闭时,它使用Activator.GetOjbect获取对服务器对象的引用

,然后调用Notify方法。如果服务器仍在运行,那么Notify工作正常,但是,如果服务器没有运行,那么客户端只需挂起即可。在方法调用上(当我使用VS调试它时,它会从Notify调用返回
,我必须终止该过程)。


当我做一个netstat,它显示服务器正在监听的端口是

仍然在LISTENING-status中。


有没有办法强行杀死或关闭这个港口?


任何帮助都会非常感激!

谢谢

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

推荐答案

如果通话时间过长,请将其线程化并终止线程。


Rob。


" Jako Menkveld" < JA *********** @ envalue.ch>在留言中写道

news:uk ************** @ 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...
我在建一个相对简单的客户端 - 服务器应用客户端的一个功能是在终止时通知服务器,这一切都可以正常工作。
服务器在客户端停止之前出现问题,在
中,客户端挂起,等待与服务器通话。

这是如何工作的:
服务器:开始监听tcp端口,比如3000(通过注册一个TcpServerChannel并调用RegisterWellKnownServiceType)。
当我关闭服务器时,我调用了对象的RemotingServices.Disconnect,然后我调用StopListening为
TcpServerChannel,然后我调用ChannelServices.UnregisterChannel。
客户端:当它关闭时,它使用Activator.GetOjbect获取对服务器目标的引用
然后调用Notify方法。如果服务器仍在运行,那么Notify工作正常,但是,如果服务器没有运行,则客户端只是挂起。在方法调用上(当我使用VS调试它时,它永远不会从Notify调用返回并且我必须终止进程)。

当我执行netstat时,它表明服务器正在监听的端口仍然处于LISTENING状态。

是否有任何强行杀死或关闭此端口的方法?

任何非常感谢帮助!
谢谢
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



Rob


我会给你一个尝试。你是说没有办法从服务器端关闭插座

那么?


谢谢

Jako

Rob R. Ainscough < RO ***** @ pacbell.net>在消息中写道

news:eL ************** @ TK2MSFTNGP15.phx.gbl ...
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...
线程化并终止线程如果通话时间太长。

Rob。

Jako Menkveld < JA *********** @ envalue.ch>在消息中写道
新闻:英国************** @ 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...
我正在建立一个相对简单的客户 - 服务器应用。客户端的一个功能是在终止时通知服务器,这一切都可以正常工作。
服务器在客户端停止之前出现问题,在
中,客户端挂起,等待与服务器通话。

这是如何工作的:
服务器:开始监听tcp端口,比如3000(通过注册一个TcpServerChannel并调用RegisterWellKnownServiceType)。
当我关闭服务器时,我调用了对象的RemotingServices.Disconnect,然后我调用StopListening为
TcpServerChannel,然后我调用ChannelServices.UnregisterChannel。
客户端:当它关闭时,它使用Activator.GetOjbect获取对服务器目标的引用
然后调用Notify方法。如果服务器仍在运行,那么Notify工作正常,但是,如果服务器没有运行,则客户端只是挂起。在方法调用上(当我使用VS调试它时,它永远不会从Notify调用返回并且我必须终止进程)。

当我执行netstat时,它表明服务器正在监听的端口
仍然处于LISTENING状态。

有没有办法强行杀死或关闭此端口?
<我非常感谢任何帮助!
谢谢
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




Jako Menkveld写道:
Jako Menkveld wrote:
Rob

我会试一试。你是说没有办法从服务器端关闭
套接字呢?
Rob

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




1.如果服务器进程(不是appdomain)在没有关闭的情况下死掉操作系统将杀死它。

操作系统将杀死它。


2.如果服务器死机没有
$ b,TCP本身应该给客户一个错误$ b关闭连接。也许它被.NET远程处理忽略了?


我不明白的是你的netstat显示端口仍然是服务器退出后听取的
。服务器进程是否真的退出了?



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?


这篇关于如何“杀死”一个tcp端口......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆