Android Http Connection
<p>I have an Android application which needs the server send packages from time to time. So I use a while in the servlet of the server. But I don't know how to receive them in my android program.
Here are the codes:</p>

<pre><code>public class PushServlet extends HttpServlet {
public static final Integer INTEVAL = 1000;

/**
 * 
 */
private static final long serialVersionUID = 6305939736003437611L;

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    process(request, response);
}

public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    process(request, response);
}

public void process(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    TUserinfo user = (TUserinfo) request.getSession().getAttribute(
            "TUserinfo");
    if (user == null) {
        System.out.println("user is null!!!!!!!!push servet exit!!!!!!!!");
        return;
    }
    response.setCharacterEncoding("UTF-8");
    response.setContentType("application/json;charset=UTF-8");

    PrintWriter pr = response.getWriter();

    try {
        while (true) {
            Map map = (Map) request.getServletContext().getAttribute(
                    user.getId().toString());
            if (map == null) {
                System.out.println("map is null!!!" + user.getId()
                        + "!!!!push servet exit!!!!!!!!");
                pr.flush();
                pr.close();
                return;
            }
            JSONObject object = PushUtil.checkMap(map);

            if (object.size() &gt; 0) {
                pr.print(object);
                pr.flush();
            }
            Thread.sleep(INTEVAL);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

}
</code></pre>

<p>}</p>
