Democratic Underground Latest Greatest Lobby Journals Search Options Help Login
Google

Very general development question regarding polling

Printer-friendly format Printer-friendly format
Printer-friendly format Email this thread to a friend
Printer-friendly format Bookmark this thread
This topic is archived.
Home » Discuss » DU Groups » Computers & Internet » Computer Help and Support Group Donate to DU
 
DaveJ Donating Member (1000+ posts) Send PM | Profile | Ignore Sun Aug-31-08 05:25 PM
Original message
Very general development question regarding polling
Not election statistics polling, but what client/server software sometimes must do. I know there are folks here who have done some development in the past and are aware of client/server concepts.

I need my website to be able to send a signal to an application running on a client PC. The notification can come at any time, and is triggered when someone presses a button on the webpage. The only way I know how to do it is to make the client app poll the server every 4 seconds or so. That's fine until I have 1000 clients all polling the server at the same time. Does anyone know how to reliably make a web server send a notification to make a client wake up? Or is this simply impossible given general security architectures, anti-spyware, firewalls, etc?

I've tried posting messages on programming forums and have not received any kind of solid solution, so I thought I'd try here one last time, otherwise I'm just going to use polling for now and try to put the other way, callbacks, out of my mind.

Do I have little choice but to use polling? If not what is the best way to send a notification to a client?
Printer Friendly | Permalink |  | Top
ChromeFoundry Donating Member (1000+ posts) Send PM | Profile | Ignore Sun Aug-31-08 11:20 PM
Response to Original message
1. There are several ways to do this...
but it all depends on where your clients are located and your limitations of firewalls.

One of the easiest methods would be to have each client initiate a connection to a server's listening service (or daemon for the Linux/UNIX folks). This is similar to how a Chat client would work. The client doesn't poll, but would just establish a connection to a port and sit there waiting for the server to send a message/event to all connected clients. This would work well in a LAN environment because you would have full control over the TCP/UDP port which the server would listen on.

Another method that works well over a slower network connections (like the Internet) would be to setup a web service that the clients could request if a pending event has occurred. The server could periodically look for queued events in something like a database, caching the events so that database hits do not occur for every client request would offer a lot of scalability.

Hope this gives you some ideas...
Printer Friendly | Permalink |  | Top
 
DaveJ Donating Member (1000+ posts) Send PM | Profile | Ignore Mon Sep-01-08 01:27 AM
Response to Reply #1
2. This is great help...
Edited on Mon Sep-01-08 01:54 AM by djohnson
I have looked into both those options but I didn't fully understand either, and so I stopped before I got all the way to the end because I didn't know if they would really work.

I imagine the first I'd run into firewall issues if I planned on distributing software to lots of different places. I also do not need that much speed, maybe just 5 second response time or less.

I'd prefer to use standard http binding, with no need for configuring ports or anything like a static server IP, or full control of the server (I'm using an inexpensive hosting plan where I would not be able to configure ports or anything -- I could use my server at work but would prefer not).

Regarding the second technqiue, I just started learning about web services about a month ago when I started using Windows Communication Platform (WCF). So I still don't have much of a general understanding of how they work -- I just created a few operations that can be called from the client so they don't have to be on the client. But the client "requesting a pending event" sounds like exactly what I need.

If I understand this option correctly, it sounds sort of like polling but not exactly. As if the client can call an method (operation/function) on the server, and the method can just wait, stop before returning a value, until it has something? Is it really that simple? Is this where I just need to handle threads so neither side locks up while waiting. If that's it, I think I've got it.

I'm pretty sure the client application would lock up while waiting for a function to return a value so I'd definitely have to place that callback in its own thread. On the server, inside the (say, getNotify) method it could just loop until an event is found in the database, but that would be massively innefficient, so I'd have to think of some way to get the database operation to trigger the getNotify operation without the need for looping. I guess that would require threading too? Do you think a hosted plan (I have discountASP.net) would let me do that on the server?
Printer Friendly | Permalink |  | Top
 
ChromeFoundry Donating Member (1000+ posts) Send PM | Profile | Ignore Tue Sep-02-08 10:36 PM
Response to Reply #2
3. on using a web service...
all you need is a dll that would periodically update a cached global DataTable via a DataReader object, called through a Timer class. The listener would just execute a SQLCommand.ExecuteQuery method, clear the table and iterate through the rows returned rows and re-populate the global DataTable.

To ensure that requests do not retrieve an incomplete set of data as the DataTable is being refreshed, declare a public boolean isRefreshing variable that is set to true just before the DataTable.Clear method is called; and false after all rows are added.

The request would need to check the isRefreshing variable's state before converting the DataTable Rows into XML, returned to the client.

It would also be wise to implement some sort of integer iReadLocks and iReadWaits variables that would pause the Timer event while data reads are performed on the DataTable until it the iReadLocks value is decremented back to zero. You may wish to use a Double-buffer method to home your DataTable object; an object Clone method is much faster than iterative Row.Add method calls. This would offer the least amount of latency for fulfilling client requests.

Make sure you setup an Application namespace in IIS for the site, and use Host-Header redirection if you only have a single IP address available on your server/virtual machine.

hope this helps...
Printer Friendly | Permalink |  | Top
 
DaveJ Donating Member (1000+ posts) Send PM | Profile | Ignore Tue Sep-02-08 11:55 PM
Response to Reply #3
4. Thanks... But it will take me time to digest all that
Maybe by the end of next weekend I'll somewhat comprehend what you just said. :-)

Just to tell you what I've done so far... I went ahead and set up a polling system since I thought it might scale easily to a non-polling system.

I'm already using an SQL server to queue events created by users of my website. And those events are read by the client app(s). The client looks for a pending event using a web service, and just as it's read the server flags the event as read, so it's not triggered again.

All is fine, but the client is still polling every 5 seconds to get the job done.

So most the logic is there in my brain except for the mechanism of sending a notification to the client without polling.

Are you sure you are telling me how to eliminate polling? That's what I'm having trouble understanding.

BTW, I can tell you have worked with web services since you're talking about converting a datatable to XML... So far I haven't had to think about that using WCF. But maybe I'm wrong, maybe that is the key to understanding the scenario, I've only been doing this a short time.

I'm still mentally blocked when it comes to how a server can notify a client at any time. Maybe it can't be done with http protocol? If not, no big deal. I could give the end user the option of opening up a port or polling, whichever they prefer. But the port option would be way down the road, after I can afford to hire someone else to do the port option.
Printer Friendly | Permalink |  | Top
 
ChromeFoundry Donating Member (1000+ posts) Send PM | Profile | Ignore Wed Sep-03-08 06:03 AM
Response to Reply #4
5. This looks very simular to what you are attempting to do
http://www.codeproject.com/KB/webservices/WebServiceWithEvents.aspx

Take a read through, you may get some ideas to assist in your design.
Printer Friendly | Permalink |  | Top
 
DaveJ Donating Member (1000+ posts) Send PM | Profile | Ignore Wed Sep-03-08 08:50 PM
Response to Reply #5
6. I think this uses some kind of port based protocol
I downloaded the code and there is some protocol named WebServiceSoap, and I also noticed a line in the code that says http://localhost:19269/WebService.asmx, which seems to indicate that the technique involves utilizing a port, judging by the number 19269.

At the moment I just want to use my cheap DiscountASP.net plan and not invest in a dedicated server that allows full control of ports. So I'm stuck with plain http protocol for now.

So I think my thought about later having the option of polling or opening a port is still the way to go. Some IT managers may prefer one to the other anyway. Polling should be simpler, while using a port may be blocked by some firewalls.

That's okay, I'm happy with the current plan. My project is rolling along now, this was just a small bump in the road that I think I'm past now, with your help at putting the architecture into perspective. Your help is greatly appreciated, it's very difficult to find comprehensive thoughts on these matters.
Printer Friendly | Permalink |  | Top
 
DU AdBot (1000+ posts) Click to send private message to this author Click to view 
this author's profile Click to add 
this author to your buddy list Click to add 
this author to your Ignore list Mon May 06th 2024, 11:37 PM
Response to Original message
Advertisements [?]
 Top

Home » Discuss » DU Groups » Computers & Internet » Computer Help and Support Group Donate to DU

Powered by DCForum+ Version 1.1 Copyright 1997-2002 DCScripts.com
Software has been extensively modified by the DU administrators


Important Notices: By participating on this discussion board, visitors agree to abide by the rules outlined on our Rules page. Messages posted on the Democratic Underground Discussion Forums are the opinions of the individuals who post them, and do not necessarily represent the opinions of Democratic Underground, LLC.

Home  |  Discussion Forums  |  Journals |  Store  |  Donate

About DU  |  Contact Us  |  Privacy Policy

Got a message for Democratic Underground? Click here to send us a message.

© 2001 - 2011 Democratic Underground, LLC