How to "push" changes to clients
Categories: How-to
|
Tags: Architects, Developers, Drag & Drop, Visual WebGui Pipeline, 1. Beginner, 2. Intermediate, Integration, Pre v6.3, v6.3, v6.4 and Later, 3. Advanced
Revision:
1
Posted:
08/Jan/2007
Updated:
08/Jan/2007
Status:
Publish
Types: Article
|
In a post made by Fisherman, the following functionality was asked how implement:
"A user enters some text in a textbox. All other users (or a group of users, depending on some selection criteria) see the text in a label in their browser"
This functionality can be achieved relatively easily with VWG. VWG framework is hosted by asp.net, so in fact you can use static members (shared in vb.net) the same way you use them with regular asp.net application.
To be more specific:
1. create static (shared in vb.net) string field in some class
class PublicData
{
...
public static string SomeText;
...
}
2. set this field to be the 'Text' property of this text box
// txtUserText is TextBox
PublicData.SomeText = txtUserText.Text;
3. Now everyone can access the text that was entered through the static field
// lblMyLabel is Label
lblMyLabal.Text = PublicData.SomeText;
Regarding step 3 you'll need to make decide on whether to "Push" or "Pull" the text. By saying "Push", I mean to automatically (without making the users explicitly asking for it) update the users' label whenever the text is changed. And "Pull" is the opposite, like making then click "refresh" button to refresh this label.
Implementing the "Pull" method I is quite trivial and i think requires on farther explanation. But I'm guessing you that most developers will prefer the "Push" method.
Implementing "Push" is a bit trickier because it requires usage of events and timer. I added a sample application that demonstrates it. Let's break apart the push into 2 small pushes:
1. Push the text to the label.
The main idea is to raise an event whenever the text is changed. Subscribe the form that contains the label to this event and set the label's 'Text' property whenever the event is raised.
2. Push the change in the label to the browser.
This can be done easily by adding timer control (VWG timer) to the form and invoke its 'Start' method on Form_Load and subscribe to the timer Tick event.
The mentioned in section 2 will cause the timer to trigger a critical event (event that make the browser to the flush to the server the queue of all non critical events happed before the critical event the critical event itself). Don't set the timer interval property to be too small, if you do you might experience bad performance. I think rule of thumb can be at least 10000 (10 seconds). To be more accurate mentioned above it is more a "pull" method then a "push", although it gives users the illusion of "pull" method.
In Web, there no real push from server to client since http protocol dictates that all communication between server and clients starts from request.
Note: Codes are submitted as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.
Terms of Agreement:
By using this code, you agree to the following terms...
1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.
3. You may link to this code from another website, but ONLY if it is not wrapped in a frame.
4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
Regarding step 3 you'll need to make decide on whether to "Push" or "Pull" the text. By saying "Push", I mean to automatically (without making the users explicitly asking for it) update the users' label whenever the text is changed. And "Pull" is the opposite, like making then click "refresh" button to refresh this label.
Implementing the "Pull" method I is quite trivial and i think requires on farther explanation. But I'm guessing you that most developers will prefer the "Push" method.
Implementing "Push" is a bit trickier because it requires usage of events and timer. I added a sample application that demonstrates it. Let's break apart the push into 2 small pushes:
1. Push the text to the label.
The main idea is to raise an event whenever the text is changed. Subscribe the form that contains the label to this event and set the label's 'Text' property whenever the event is raised.
2. Push the change in the label to the browser.
This can be done easily by adding timer control (VWG timer) to the form and invoke its 'Start' method on Form_Load and subscribe to the timer Tick event.
The mentioned in section 2 will cause the timer to trigger a critical event (event that make the browser to the flush to the server the queue of all non critical events happed before the critical event the critical event itself). Don't set the timer interval property to be too small, if you do you might experience bad performance. I think rule of thumb can be at least 10000 (10 seconds). To be more accurate mentioned above it is more a "pull" method then a "push", although it gives users the illusion of "pull" method.
In Web, there no real push from server to client since http protocol dictates that all communication between server and clients starts from request.
About the author
Related Articles
|
How-to
|
|
|
Tags:
Architects, Developers, C#, XML, 2. Intermediate, 3. Advanced, AJAX, ASP.NET, Pre v6.3, v6.3, v6.4 and Later
|
|
|
Tags:
Developers, Data Binding, Events, 1. Beginner, 2. Intermediate, Integration, Pre v6.3, v6.3, v6.4 and Later, 3. Advanced
|
|
|
Tags:
Architects, Developers, 3. Advanced, Pre v6.3, v6.3, v6.4 and Later
|
|
|
Tags:
Architects, Developers, 2. Intermediate, 3. Advanced, Pre v6.3, v6.3, v6.4 and Later
|
|
|