Presentation is loading. Please wait.

Presentation is loading. Please wait.

Pushlets Introduce A comet framework Zhang Haipeng 2011-4-10.

Similar presentations


Presentation on theme: "Pushlets Introduce A comet framework Zhang Haipeng 2011-4-10."— Presentation transcript:

1 Pushlets Introduce A comet framework Zhang Haipeng 2011-4-10

2 Index Comet Pushlets Applications Other…

3 What is Comet? Comet is a web application model in which a long-held HTTP request allows a web server to PUSH data to a browser, without the browser EXPLICITY requesting it.

4 HTTP

5 Pushlets An Free and Open Source HTTP-based publish/subscribe framework. Pushlets are a servlet-based mechanism where data is pushed directly from server-side Java objects to HTML pages within a client-browser without using Java applets or plug-ins. This allows a web page to be periodically updated by the server

6 Publish/Subscribe

7 How to use pushlets?? -- integration with your web app Add pushlets.jar to your classpath Add javascript to you web app Config web.xml pushlet nl.justobjects.pushlet.servlet.Pushlet 1 pushlet /pushlet.srv

8 How to use pushlets?? -- message receiver window.onload = page_init; var displayDiv = null; function page_init(){ displayDiv = document.getElementById("displayDiv"); p_join_listen('/chat'); } function onData(event) { content = event.get('msg'); var newDiv = document.createElement("DIV"); newDiv.innerHTML = content; displayDiv.appendChild(newDiv); }

9 How to use pushlets?? -- send msg with javascript window.onload = page_init; function page_init(){ p_join_listen('/chat'); } function sendMsg(){ var inputObj = document.getElementById("txt"); var txt = inputObj.value; p_publish('/chat', 'msg', txt); }

10 How to use pushlets?? -- send message with Java Event anEvent = null; anEvent = Event.createDataEvent("/chat"); anEvent.setField("msg", "servlet sended!"); Dispatcher.getInstance().broadcast(anEvent);

11 How to use pushlets?? -- send message with java public class MyEventSource extends EventPullSource { @Override protected long getSleepTime() { return Rand.randomLong(3000, 5000); } @Override protected Event pullEvent() { Event event = Event.createDataEvent("/chat"); event.setField("msg", new Date().toString()); return event; } Source.properties source7=com.chinaoryx.web.MyEventSource

12 Displayer javaScript API


Download ppt "Pushlets Introduce A comet framework Zhang Haipeng 2011-4-10."

Similar presentations


Ads by Google