如何检查服务器是否打开远程连接?
我正在像这样设置远程连接:
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");
但是连接经常丢失并且需要重新建立,如何检查连接是否仍然打开?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(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.