Notify your coworkers any message
anywhere
UDAParts
support@udaparts.com
Updated on Feb. 24, 2007
Contents:
Introduction
Polling
Chat
service or real-time notification
Built-in
bi-directional asynchronous chat service
Available sample
projects
Real-time
notification in SocketPro
Set
up your real-time notification on server side for broadcasting messages
No
setting required for sending private messages
Setting
for broadcasting messages on server side
Fast and
intelligent order processing
Send your coworkers
messages on both client and server sides
1. Introduction
Suppose that a team of coworkers
shares a center data store like a database, a file, memory cache or whatever
else, we want our application has an advanced feature like Yahoo, Microsoft
messengers or Internet chat to ensure that
everyone has the latest information after anyone of coworkers makes any change to the
shared data
store. Polling
-- Basically there are two ways, polling and notification, to
enable a team of coworkers to share a center data store. The first way is that
each of coworkers sends the remote data store a request
to get the latest version of required data periodically at a predefined time
interval. This method is called as polling, but it has two basic flaws: (1) that it consumes a
large portion of network bandwidth, and (2) that other workers can never get the
latest version of data in real-time fashion. Therefore, you can not use polling
if you want to support a large number of clients. Overall, polling is not a good
choice for real professional software.
Chat service or real-time
notification -- The
second way is that a coworker sends a message to one or more coworkers right after
he or she has just made a change to the shared data store. Afterwards, coworkers pick up the
message, analyze it and send a request to the data store for the latest version
of just wanted data. The second way is slightly more complicate than the
first one, but it is much more elegant and eliminates the two basic flaws of the
first way. It can supports much more clients than polling with much better
scalability. If your project requires exchanging data between clients and
server, you may need to consider re-designing your system with use of real-time
notification for better performance and supporting more clients.
Built-in
bi-directional asynchronous chat service -- SocketPro has a powerful built-in service named as chat service with the
second way for you to notify one or more coworkers in real time fashion, when there is an
interesting event to a shared data store on both client and server sides.
Because SocketPro fully supports Pocket PC and smart phone with the same set of
APIs, you can also use SocketPro to notify a team of coworkers from these
devices easily. Further, all of socket connections inherit this service
automatically, right after a client calls the method IUSocket::SwitchTo. 2.
Available sample projects
There are many samples available for
you to experiment this powerful service, as listed in the below.
C++:
SampleTwo in the directory ..\tutorial\CPlusPlus\SampleTwo,
..\samples\others\server\RemoteConnector.
C#:
SampleTwo in the directory ..\tutorial\CSharp\SampleTwo.
VB6 and VB.NET:
SampleTwo in the directories ..\tutorial\VBNET\SampleTwo, ..\samples\others\vb6\chatTest,
DBatHome, and OneBigBatch.
PocketPC and Smartphone: ..\SocketPro\samplesCE\DevTest 3.
Real-time notification in SocketPro
SocketPro chat service is simple to
use and understand. It supports exchanging messages in two ways: (1) sending
message privately between two
clients and (2) broadcasting messages onto one or more groups of clients. You can
send messages at either client or server side and messages can be any data like
a string, a primitive data and an array of primitive data. See the
following figure.
With help of SocketPro, you can share chat service with another service like OLEDB
database service as shown inside the sample projects DBAatHome and OneBigBatch
without requiring a new socket connection because all of other services inherit
chat service. Additionally, you can use an
independent socket connection to exchange messages with other clients.
4. Set
up your real-time notification on server side for broadcasting messages
No
setting required for sending private messages -- By default, SocketPro is enabled for
sending messages between two clients (P2P). If you just exchange P2P messages
only, you will not be required to do any
thing at all at server side. The major API methods for sending private messages
are: IUChat::SpeakTo (client)/SpeakTo (server), IUFast::SpeakToEx (client)/SpeakToEx
(server), IUChat::SendUserMessage (client)/SendUserMessage (server), and
IUFast::SendUserMessageEx (client)/SendUserMessageEx (server).
Setting
for broadcasting messages on server side -- If you want to broadcast a message
onto multiple clients in groups, you are required to set up chat groups first on
server side. You may also set up auto-notification messages when a client enter
or exit from a group. See the following code for creating a set of discussion
groups and enabling all of joined clients notified when a client exits from or
join into anyone of groups:
SocketProServer.AddAChatGroup(1,
"High Level Management Group");
SocketProServer.AddAChatGroup(2, "Management Group");
SocketProServer.AddAChatGroup(4, "Sales Department");
SocketProServer.AddAChatGroup(8, "IT Department");
SocketProServer.AddAChatGroup(16, "Order Processing Department");
SocketProServer.GroupsNotifiedWhenEntering = -1; //all
groups
SocketProServer.SetGroupsNotifiedWhenExiting = -1; //all
groups
Note
that SocketPro supports 32 different chat groups at most. All of group IDs
except the group ID one must be divided by 2 without remaining so that a client
can broadcast a message onto multiple groups with bit-wise OR operation with one
call. Otherwise,
the method AddAChatGroup will return false.
If you want to enable a client to use
an dedicated socket connection to send messages out, you should also set an
independent chat service with the following code on server side:
m_ChatSvs = new
CNotificationService();
m_ChatSvs.AddMe((int)tagServiceID.sidChat, 0,
tagThreadApartment.taNone);
All
of the above server samples show you how to set up chat
service.
The major API methods for broadcasting messages are: IUChat::Speak
(client)/Speak (server) and IUFast::SpeakEx (client)/SpeakEx (server). 5.
Fast
and intelligent order processing
Suppose a sale representative gets an order from a customer, the representative
will send a message to order processing department after he or she inputs a set
of data into a shared database. The code will be something like the following:
BeginBatching();
Speak(16, "I
am going to enter an order into our database. Order processing department gets
prepared to processing the order"); //16 --
Group ID for Order Processing Dept
OpenDatabase("SomeConnectionStringToADatabase");
ExecuteSQL("SomeSQLInputStatement1");
ExecuteSQL("SomeSQLInputStatement2");
ExecuteSQL("SomeSQLInputStatement3");
......
Commit(true); //ask
server returns result in one batch
WaitAll();
if (SomethingIsWrong)
{
BeginBatching();
Speak(8,
"I can't input order data into our database. IT
department needs to fix the problem immediately!");
Speak(16,
"Something is wrong with our database. Order is not
ready to process at the moment");
Commit(true);
}
else
Speak(16,
"An new order is input into database. Order
processing department is able to process it now");
Once a successful message arrives Order Processing Department, one employee may
use the following code to process the message.
BeginBatching();
Speak(16, "I'll
take the order and process it. Please don't take the order again.");
OpenDatabase("SomeConnetionStringToADatabase");
ExecuteSQL("SomeSQLQueryforTheOrder");
......
ExecuteSL("SomeSQLUpdateStatement");
Commit(true);
WaitAll();
if (SomethingIsWrong)
{
Speak(8 + 4 +
16, "I can't process the order because of our IT
problem. IT department needs to fix the problem immediately!"); //notify
three groups in one call
}
else
Speak(16 + 4,
"Order is successfully processed"); //notify
two groups in one call
The above notifications will significantly speed up the processing. If there is
any thing wrong, other coworkers will be notified immediately. This is just one
sample only. It is not difficult at all to find many many more samples like this
one. For how to track these
notification on client side, please see the above samples. It is a really simple
step. 6. Send your coworkers
messages on both client and server sides
As shown
in tutorial two and in the section 4, SocketPro supports bi-directional real
time notification on both client and server sides. Server side notification is
faster than client side notification. You can embed real-time notification to
server code so that your service is more powerful and smarter.
************************ |