如何检查远程连接是否对服务器开放?

时间:2021-01-05 00:30:53

I'm setting up my remoting connection like this:

我正在设置我的远程连接,如下所示:

port = new Random().Next(REMOTING_PORT_MIN, REMOTING_PORT_MAX);
TcpChannel chan = new TcpChannel(port);
ChannelServices.RegisterChannel(chan, false);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(NotificationService), "CallOnMe.rem", WellKnownObjectMode.Singleton);

notService = new NotificationService();
notService.NotificationMessageEvent += new NotificationService.NotificationMessageEventHandler(notService_NotificationMessageEvent);

RemotingServices.Marshal(notService, "CallOnMe.rem");

But every so often the connection is lost and needs tp be re-established, how can I check to see if the connection is still open?

但是经常连接丢失并需要重新建立,我如何检查连接是否仍然打开?

1 个解决方案

#1


I don't know any method where you can check if the connection is still active. But you can implement this quite easy, by either calling periodically a dummy method on the server, or do something else with the remoting object. Then you can check for the exception, and try to reconnect.

我不知道您可以检查连接是否仍处于活动状态的任何方法。但您可以通过在服务器上定期调用虚方法或使用远程处理对象执行其他操作来轻松实现此操作。然后,您可以检查异常,并尝试重新连接。

#1


I don't know any method where you can check if the connection is still active. But you can implement this quite easy, by either calling periodically a dummy method on the server, or do something else with the remoting object. Then you can check for the exception, and try to reconnect.

我不知道您可以检查连接是否仍处于活动状态的任何方法。但您可以通过在服务器上定期调用虚方法或使用远程处理对象执行其他操作来轻松实现此操作。然后,您可以检查异常,并尝试重新连接。