?? simplelistener.java
字號:
// Copyright (c) 2000 Just Objects B.V. <just@justobjects.nl>// Distributable under LGPL license. See terms of license at gnu.org.package nl.justobjects.pushlet.test;import nl.justobjects.pushlet.client.PushletClient;import nl.justobjects.pushlet.client.PushletClientListener;import nl.justobjects.pushlet.core.Event;import nl.justobjects.pushlet.core.Protocol;import nl.justobjects.pushlet.util.PushletException;/** * Demonstrates join-listen service. * * The pushlet protocol supports the "join-listen" service * which allows stateless (e.g. RESTful) clients to join/subscribe/listen * using a single HTTP request. * * @version $Id: SimpleListener.java,v 1.3 2005/03/14 14:07:23 justb Exp $ * @author Just van den Broecke - Just Objects © **/public class SimpleListener implements PushletClientListener, Protocol { private static String SUBJECT = "/wyyCity"; private static final String MODE = MODE_STREAM; public SimpleListener(String aHost, int aPort) { // Create and start a Pushlet client; we receive callbacks // through onHeartbeat() and onData(). try { PushletClient pushletClient = new PushletClient(aHost, aPort); pushletClient.setDebug(true); pushletClient.join(); pushletClient.listen(this, MODE, SUBJECT); p("pushletClient started"); } catch (PushletException pe) { p("Error in setting up pushlet session pe=" + pe); } } /** Error occurred. */ public void onError(String message) { p(message); } /** Abort event from server. */ public void onAbort(Event theEvent) { p("onAbort received: " + theEvent); } /** Data event from server. */ public void onData(Event theEvent) { // Calculate round trip delay System.out.println("onData output is --------"); System.out.println("theEvent.toXML() : " + theEvent.toXML()); System.out.println("theEvent.toQueryString() : " + theEvent.toQueryString()); System.out.println("here is the city :" + theEvent.getField("city")); System.out.println("p_event :" + theEvent.getField("p_event")); System.out.println("p_time : " + theEvent.getField("p_time")); System.out.println("default p_time : " + theEvent.getField("p_time", "default p_time")); System.out.println(); } /** Heartbeat event from server. */ public void onHeartbeat(Event theEvent) { p("onHeartbeat received: " + theEvent); } /** Generic print. */ public void p(String s) { System.out.println("[SimpleListener] " + s); } /** Main program. */ public static void main(String args[]) { if (args.length == 0) { System.out.println("args.length == 0"); new SimpleListener("localhost", 8080); } else if (args.length == 1) { SUBJECT = args[0]; System.out.println("args.length == 1"); new SimpleListener("localhost", 8080); } else { SUBJECT = args[0]; // args[1] and [2] should be host and port System.out.println("args.length == else"); new SimpleListener(args[1], Integer.parseInt(args[2])); } }}/* * $Log: SimpleListener.java,v $ * Revision 1.3 2005/03/14 14:07:23 justb * addded subject arg * * Revision 1.2 2005/02/28 21:21:32 justb * no chg * * Revision 1.1 2005/02/28 15:58:05 justb * added SimpleListener example * * */
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -