pushlet-UserUnicast Manual

pushlet-UserUnicast is based on a modified extension JAVA comet pushlet after implementation framework. Major expansion of the unicast real demand push function.

The method unicast pushlet can push data to the specified session (SessionID), the data is pushed to the specified user, since the SessionID can be randomly generated, can not be associated with a user, it is not according to the service field (such as the user ID, user name) and so pushed to the specified user.

Core implementation features:



pushlet-userunicast API:



Multi-user connection configuration parameters:

When multiple clients to connect simultaneously use the same user ID PL.userId can be more connected to the push type parameters byunicast.type user, unicastUserId (Event, userId) method uses multiple connections that value as the user push the way.

In pushlet.properties can configureunicast.type parameters, optional value:

pushlet-userunicast Users push the use of steps and examples:

  1. Jar package introduced for the project under lib:

  2. Join the configuration file resource under the src orWEB-INF in:

  3. Need to subscribe to an event added to the Web project client under the client JS file:

  4. In web.xml core Servlet controller configurationpushlet

  5. Clients subscribe to receive messages index.jsp
    Use PL.userId attribute specifies the string that identifies the client, server-side push data in accordance with this identity to the client

     <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
         <title>Users receive a message page</title>
         <script type="text/javascript" src="js/ajax-pushlet-client.js"></script>
         <script type="text/javascript">
             PL.userId = "JAY";
             function onData(event) {
                 document.getElementById("msg").innerHTML = document
                         + event.get("msg") + "<br/>";
         <div id="msg"></div>
         <br />
         <br />
         <br />
         <a href="publish.jsp" target="_blank">Push back page news</a>
  6. Servlet server-side push test data
    Use Dispatcher.getInstance () unicastUserId (Event, userId user ID); push data to the specified client user ID, userId user ID corresponding PL.userId.

     package servlet;
     import java.io.IOException;
     import javax.servlet.ServletException;
     import javax.servlet.http.HttpServlet;
     import javax.servlet.http.HttpServletRequest;
     import javax.servlet.http.HttpServletResponse;
     import nl.justobjects.pushlet.core.Dispatcher;
     import nl.justobjects.pushlet.core.Event;
     public class MsgPushServlet extends HttpServlet {
         protected void service(HttpServletRequest req, HttpServletResponse resp)
                 throws ServletException, IOException {
             // Push message
             String msg=req.getParameter("msg");
     //        String userId="JAY";
             // Push users
             String userId=req.getParameter("userId");
             // Push-user multi-way connection
             String type=req.getParameter("type");
             // Event objects and data
             Event event = Event.createDataEvent("/push/hello");
             event.setField("msg", msg); //Chinese do not need to be converted to ISO-8859-1
             // According unicast.type push parameter values ​​to the specified user pushlet.properties
     //        Dispatcher.getInstance().unicastUserId(event,userId);  
              // Pushed to the specified user from the specified type type
             Dispatcher.getInstance().unicastUserId(event, userId, type); 

    The servlet web.xml configuration

  7. Call Servlet, publish pages publish.jsp push message

     <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
          <title>Published push message</title>
         <h1>Published need to push the message:</h1>
         <form action="servlet/MsgPushServlet" method="post" target="pushFrame">
                 push userId: <input type="text" name="userId" value="JAY" />
                 push message: <input type="text" name="msg" >
                 push type:  
                 <input type="radio" name="type" id="all" value="all" checked="checked">
                 <label for="all">ALL(all connection)</label>
                  <input type="radio" name="type" id="first" value="first">
                  <label for="first">FIRST (first connection))</label>
                  <input type="radio" name="type" id="last" value="last">
                  <label for="last">LAST (last connection))</label>
             <input type="submit" value="push">
         <iframe name="pushFrame" style="display: none;"></iframe>


If you have more comments, suggestions or ideas, please contact me.

Contact, feedback, customization, training Email: inthinkcolor@gmail.com