TCP/IP .NET应用程序检测到客户端是否处于活动状态? [英] TCP/IP .NET application detect client active or not?

查看:145
本文介绍了TCP/IP .NET应用程序检测到客户端是否处于活动状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

现在我正在开发网络服务应用程序.有两个
应用.一种是服务器模式,一种是客户端.当服务器
应用程序启动后,我在服务器和客户端之间建立了连接.
客户端应用程序将原始字符串(例如name | value1 | value2 | date)发送到
用户在客户端应用中按下按钮时的服务器.但是我的问题是什么时候
客户端应用程序已挂起,服务器端仍处于连接状态.那怎么能
我知道客户端计算机是否处于活动状态.哪种技术合适
对于这种情况. (我应该使用WCF吗?是更有效还是相同?).

请帮助我.

最佳rgds,
df

Hi All,

now i am developing network service application. there are two
application. one is server mode and one is client. when the server
application starts, i establish connection between server and client.
client application send raw string (e.g. name|value1|value2|date) to
server when user press button in client app. but my problem is when
client application is hanging, server side is still connected. so how can
i know client machine is active or not. What kind of technique is suitable
for this kind of situation. (should i use WCF? is it more effective or same).

pls, help me.

best rgds,
df

推荐答案

您不知道,如果通过活动"表示在页面上进行了一些工作.该服务器仅通过HTTP请求工作.用户使用页面上的控件,并且在许多情况下,这些操作无需任何回发即可全部通过JavaScript进行,也就是说,完全在客户端进行.这样的仅客户端活动的一个示例是仅在输入控件中键入一些文本,除非您专门处理用户的按键操作,但这将是非常低效的.是的,客户端-服务器模型很糟糕. (此外,客户可以简单地挠头思考他的页面;您是否称其为活动"?:-))

无论您使用什么,都受该客户机-服务器模型的常规标准Web浏览器操作的限制.也许,您应该回顾一下不活动的概念,否则它将无处可去.

有一些参考资料可以帮助您对问题有所了解,甚至可以得到一些启发.请参阅:
http://en.wikipedia.org/wiki/Server-push [ http://en.wikipedia.org/wiki/Pull_technology [ http://en.wikipedia.org/wiki/Inversion_of_control [来自同一端口号的多个客户端 [
You cannot know that, if by "active" you mean doing some work at your page. The server only works by HTTP requests. The user work with the controls on the page, and in many cases it''s done without any postback, all via JavaScript, that is, fully on the client side only. An example of such client-side only activity would be just typing some text into a input control, unless you specially handle the user''s key presses, but that would be highly inefficient. Yes, client-server model sucks. (Besides, a customer can simply scratch her/his head thinking over your page; would you call it "active" or not? :-))

No matter what you use, it is all limited by normal standard Web browser operation with that client-server model. Perhaps, you should review your concept of inactivity, otherwise it will lead you nowhere.

There are the references to help you to gain some vision on the problem, maybe even some inspiration. Please see:
http://en.wikipedia.org/wiki/Server-push[^],
http://en.wikipedia.org/wiki/Pull_technology[^],
http://en.wikipedia.org/wiki/Inversion_of_control[^].



Please also see my past answer:
Multple clients from same port Number[^].

—SA


在这种情况下,我不会保持连接活动.不管使用低级TCP套接字还是其他高级协议,这都是相当大的开销(资源被保留).当服务器与客户端联系时,这也不是一个好方法.
尽管构建简单的客户端-服务器TCP架构看起来很简单,但是与框架支持的服务模型相比,您获得的收益比您想象的要少.
据我了解,您正在制作一个厚实的应用程序,而不是基于Web浏览器的应用程序.我想这是一个业务应用程序,而不是实时应用程序.假设是后者,您必须这样考虑您的任务:您有一个服务提供者(您的服务器收集数据),您有服务使用者(发送数据的客户端),并且有一种传输方法.这些是不同的关注点.
WCF只是处理此三角形的一种方法.您问效率,但是从哪个方面讲?编码,运行时资源,响应能力,容错能力...?无论哪种方式,都可以让框架为您工作.
考虑阅读本文:
WCF或ASP.NET Web API?我在这个问题上的两分钱 [ ASP.NET WebAPI:MVC4和WebAPI入门 [ http://www.developer.com/net/asp/using-an-asp.net-web-api-using-httpclient.html [ ^ ].

这样,您可以确定,将来对应用程序或维护的任何升级都将更容易执行.

祝你好运!
I would not keep connection alive it this case. Indifferent of low level TCP socket or other higher level protocol is used, it is a considerable overhead (resources are kept reserved). And it is not a good approach either, when the server is contacting the client.
Although it looks straightforward to build a simple client-server TCP architecture, you gain less than you would think - compared to a framework supported servicing model.
As I understood you are making a thick application, not a web browser based one. And I suppose it is a business application, not a real-time one. Assuming the later, you have to think of your task this way: you have a service provider (your server collecting the data), you have service consumers (the clients sending the data), and there is a transport method. These are different concerns.
WCF is just one approach to deal with this triangle. You ask about efficiency, but in what aspect? Coding, runtime resources, responsiveness, fault tolerance,...? Either way, let the framework work for you.
Consider reading this article: WCF or ASP.NET Web APIs? My two cents on the subject[^]

From what I can see of your task, I would use the new WebAPI to build the service provider (self-hosted or inside IIS) : ASP.NET WebAPI: Getting Started with MVC4 and WebAPI[^]. You don''t need to create web interface, only expose your method(s), and you can consume them easily even from a WindowsForms application: http://www.developer.com/net/asp/consuming-an-asp.net-web-api-using-httpclient.html[^].

This way you can be sure, that any future upgrade of your application or maintenance will be easier to perform.

Good luck!


这篇关于TCP/IP .NET应用程序检测到客户端是否处于活动状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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