Home Products Consulting Download Registration Support Events


Notify your coworkers any message anywhere

Updated on Feb. 24, 2007

        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
Further readings

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.
    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.
        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 as shown in the below:

PushManager.AddAChatGroup(1, "High Level Management Group");
PushManager.AddAChatGroup(2, "Management Group");
PushManager.AddAChatGroup(4, "Sales Department");

PushManager.AddAChatGroup(6, "R&D Department");
PushManager.AddAChatGroup(8, "IT Department");
PushManager.AddAChatGroup(16, "Order Processing Department");

        Note that SocketPro supports any number of chat groups. All of group identification numbers must be unique except zero.
        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.

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:


       int []groups = {16};
        GetAttachedClientSocket().Push.Broadcast("I am going to enter an order into our database. Order processing department gets prepared to processing the order", groups); //16 -- Group ID for Order Processing Dept 
        Commit(true); //ask server returns result in one batch
        if (SomethingIsWrong)

            int []groups = {8};            

            GetAttachedClientSocket().Push.Broadcast("I can't input order data into our database. IT department needs to fix the problem immediately!", groups);

            groups[0] = 16;
            GetAttachedClientSocket().Push.Broadcast("Something is wrong with our database. Order is not ready to process at the moment", groups);

             GetAttachedClientSocket().Push.Broadcast("An new order is input into database. Order processing department is able to process it now", groups); //16 -- Group ID for Order Processing Dept 


        Once a successful message arrives Order Processing Department, one employee may use the following code to process the message.


       int []groups = {16};
        GetAttachedClientSocket().Push.Broadcast("I'll take the order and process it. Please don't take the order again.", groups);
         if (SomethingIsWrong)

           int[] groups = {4, 8,16};
            GetAttachedClientSocket().Push.Broadcast("I can't process the order because of our IT problem. IT department needs to fix the problem immediately!", groups); //notify three groups in one call

            int []groups = {16,4};
            GetAttachedClientSocket().Push.Broadcast("Order is successfully processed", groups); //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.

7.    Further readings

        Real-time pushing data from SocketPro server onto browsers using SocketPro plug-in
        Pushing data from SocketPro HTTP server onto browsers through JavaScript and AJAX
        Pushing data from SocketPro HTTP server onto MS Silverlight clients
        Tutorial 2
        Push messages onto any clients from your backend databases