Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: .NET Network TCP/IP
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
Posted 10-Sep-12 17:20pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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? Smile | :) )
 
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[^].
 
[EDIT]
 
Please also see my past answer:
Multple clients from same port Number[^].
 
—SA
  Permalink  
v3
Comments
dartfrog at 12-Sep-12 23:41pm
   
Thanks, currently my application is windows service. it is not web browser based application. actually client side is blood pressure machine. when patient measured already, the data send to server using TCP/IP. my window service application that installed in server, received patient's data that sent from bp machine. for example. when user plug out network cable from bp machine, server side cannot know it is already plugged out. so connection is still established. so how should i check ?
Sergey Alexandrovich Kryukov at 13-Sep-12 1:45am
   
First, sorry that I was mistaken about a Web application or service. A more general network service is a very different story, because it does allows the server push, even via HTTP or HTTPS protocol; this is because you don't have to deal with the client confined by some rigid standards. In your settings, you can, for example, devise the application-level protocol (which you always create, even if you don't call is so) which can send "still alive" packets to the server part, as soon as such client connects to the service, the listening service accepts the connection and start receiving this packets. Here, it's important that the service keeps reference to remote sockets or instances of TpcListener (representing remote clients). On server side, this is a typical two-thread schema. The remaining problem is only the detection of "alive" status on the client side. I don't know your detail, but it seems to me that the client side has enough events. Let me understand this: is the physical measurements, the data acquisition code, runs on the client side or server side?
 
Let me give you the reference to my other answer where I describe this publisher-subscriber schema in more detail. It should certainly fit your application...
 
...Done. Please see the updated answer, after [EDIT].
 
If you provide further feedback, we can discuss your case in further detail. First of all, I need to understand where the pressure is measured, what's the major roles of the client parts and the service. Is that there is one instance of service part and several clients? (If this is so and only so, don't be surprised with this question: I've developed quite successive schema with measurements and data acquisition, where there are always multiple servers (servers-publishers, in fact), but the client (client-subscriber), in the typical practical case, could be just one.)
--SA
dartfrog at 13-Sep-12 3:07am
   
Hi my client is BP machine. so After patient measured already, BP machine send information to server that installed my window service application. Thanks
Sergey Alexandrovich Kryukov at 13-Sep-12 12:15pm
   
I see. If there a pure physical way of detecting the presence of a patient? For example, it could be two logically ORed criteria: the pressure higher than some level OR presence of pulse. The client part can monitor these or some other parameters permanently and detect if the condition of patient presence is not met during certain period of time; if that happens, the client part sends the "patient out" message to the server, when at least one of those criteria is met, is sens "patient in" message. This message is also sent right after the connection is established. And, if patient presence status on the client side is not modified since the most recent connection, nothing is sent. This way, that bad client-server polling is avoided.
 
Can it work for you?
--SA
dartfrog at 17-Sep-12 4:27am
   
for my case. polling is my only way
Sergey Alexandrovich Kryukov at 17-Sep-12 20:03pm
   
Well, if this is so (which I could believe), this is unfortunate. But is the way I suggested possible? Something based on monitoring pulse + pressure?
--SA
dartfrog at 28-Sep-12 3:31am
   
i will discuss with my technician.
Sergey Alexandrovich Kryukov at 28-Sep-12 14:01pm
   
Would be interesting to know how it goes.
Are you going to accept my answer formally now (green button)? -- thanks.
Good luck.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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!
  Permalink  
Comments
dartfrog at 12-Sep-12 23:40pm
   
Thanks, currently my application is windows service. it is not web browser based application. actually client side is blood pressure machine. when patient measured already, the data send to server using TCP/IP. my window service application that installed in server, received patient's data that sent from bp machine. for example. when user plug out network cable from bp machine, server side cannot know it is already plugged out. so connection is still established.
so how should i check ?
Zoltán Zörgő at 13-Sep-12 1:19am
   
The "blood pressure machine" part was a really important information missing from your question. Have you any possibility to change the client's software? I assume not. Is the client also waiting for some data, or just sending data? If not, that I know of no method to detect problems, since tcp connection is like a pipe. If data is flowing or not, the pipe is still there. The peer trying to send something is able to check the connection status, not the receiver. So let's suppose, you can send a configuration data or something for heart-beet ( :) ) test to the client from time to time. Try the answer of this thread, that is based on Socket.Poll.
dartfrog at 13-Sep-12 3:03am
   
thanks, i'll try out. btw client machine just sending data and no need to send any command to retrieve data.
Zoltán Zörgő at 15-Sep-12 4:53am
   
Any progress?
dartfrog at 17-Sep-12 4:27am
   
Only way is polling :(

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 9,535
1 OriginalGriff 8,295
2 Peter Leow 4,839
3 Kornfeld Eliyahu Peter 3,210
4 Maciej Los 2,301


Advertise | Privacy | Mobile
Web04 | 2.8.150327.1 | Last Updated 13 Sep 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100