Realtime Server Sent Events 17. February 2009 um 21:49 Uhr / Programming Webdesign /
Ich habe vor bei einer Webapplikation von PULL
auf PUSH
umzustellen. D.h. der Server soll die Klienten benachrichtigen dass neue Info da ist, damit die Klienten aufhören alle 20 Sekunden nachzufragen und den Server unnötig zu belasten.
Erst dachte ich an einen Java Klient, den sich jeder runterläd und der dann in einem WebView die Seite anzeigt und Events vom Server empfängt und die Daten dann updatet. Dann kam mir aber wieder der Blogeintrag Event Streaming to Web Browsers von Opera in den Sinn, ich habe mir dann mal deren Chat-Clienten angeschaut und mal alles weggelassen was man zu vernünftigen Verstehen nicht braucht, hier ist das Ergebnis:
Das Ruby Skript
#!/usr/bin/env ruby print "Content-Type: application/x-dom-event-stream\n\n" while true print "Event: new_message\n" print "data: <strong>it is now:</strong> #{Time.now.to_s}\n\n" STDOUT.flush sleep 2 end
Das HTML
<div id="message-area"></div'> <event-source src="/cgi-bin/server-event.rb" id="messages">
Das JavaScript
window.onload = function() { document.getElementById('messages').addEventListener('new_message', new_message, false); } function new_message(event) { var message = document.createElement("div"); message.innerHTML = decodeURIComponent(event.data); document.getElementById("message-area").appendChild(message); }
Was passiert ist, dass der Browser eine Verbindung zum Server aufmacht, sie dann aber nicht wieder schließt sondern offen lässt. Über diese kann dann der Server Daten an den Klienten schicken, die dieser dann wiederum mit Hilfe von ein bischen einfachem JavaScript interpretieren kann.
Da meine Webapplikation bisher sowieso den Opera 9 als Platform verlangte zahlt sich das jetzt aus. Das beste ist, ich muss warscheinlicih nur 20 Zeilen code umschreiben um von PULL
auf PUSH
umzustellen.
Da HTML5 noch ein Working Draft ist, werden sich die Namen der Tags und JavaScript-Methoden und Events höchstwarscheinlich noch ändern.
Weiterführende Links
- Event Streaming to Web Browsers
- 7.2 Server-sent events bei WHATWG HTML5
- Bug 338583 - Add support for Server-Sent DOM Events (Remote Events) - Firefox
- Bug 14997: Support for server-sent DOM events - Safari
- Comet: Low Latency Data for the Browser
- Comet (programming) Wikipedia - Eher hässliche Alternative zu Server-Events
Kommentare
Die Kommentare sind für diesen Eintrag geschlossen.
Christian Kruse aus Dortmund / NRW schrieb am 18.02.2009
Das ist aber nur sinnvoll bei geringer Besucher-Menge. Offen gehaltene Verbindungen sorgen dafür, dass (beim üblichen Apache-Prefork-MPM) das Apache-Child keine Verbindungen mehr bearbeiten kann. Wenn du jetzt 100 Besucher hast, sind 100 Apache-Prozesse also belegt. Ist MaxChilds erreicht, gibts keine neuen Prozesse. Setzt man MaxChilds zu hoch, ist der RAM voll: so ein Apache-Prozess braucht ja auch einiges an Speicher.
Fazit: lohnt sich nur, wenn man allein auf dem Server ist und/oder eine sehr geringe Besucherzahl hat.
Christian Kruse aus Dortmund / NRW schrieb am 18.02.2009
Ist die Test-Seite schon gut besucht? Der Server reagierte erst nach guten 10 Sekunden :>
pernox schrieb am 18.02.2009
Georg Helmstedt aus Gütersloh schrieb am 25.05.2009
Ich bin auch der Meinung, dass es wohl besser für's Intranet geeignet ist, da bei mir der Test noch länger als 10 Sekunden gebraucht hat. Das liegt aber zum großen Teil daran, dass wir (leider) nur eine DSL-Verbindung von 1Mbit haben und das Internet bei uns generell ziemlich langsam ist.
Aber auch in dieser modernen Zeit, wo das Streben nach immer größeren Bandbreiten ist, sollte man nicht unterschätzen, dass es immer noch Computer gibt, die über eine extrem langsame Verbindung mit dem Internet angeschlossen sind.
Aus diesem Grund würde ich eher das PULL-Event bevorzugen, obwohl ich irgendwann hoffe, dass alle Verbindungen so schnell sind, dass sich das PUSH durchsetzten wird.
Macht die ganze Sache noch interaktiver :)
Gruss Georg
bobrod23 aus Viljandi schrieb am 13.10.2009
<a href=" http://blog.sixwise.com/members/viagraonline.aspx ">buy generic viagra</a> buy diet viagra online , <a href=" http://www.1up.com/do/my1Up?publicUserId=6078588 ">buy cialis online</a> cialis soft tabs online purchase , <a href=" http://sharepointmx.mvps.org/members/buy-levitra-online.aspx ">buy levitra online</a> what does levitra look like , <a href=" http://wss-id.org/members/buy-generic-cialis-online.aspx ">buy generic cialis</a> cialis levitra viagra free sample , <a href=" http://blogcastrepository.com/members/buy_2D00_cheap_2D00_propecia_2D00_finasteride.aspx ">buy propecia</a> anybody order propecia online , <a href=" http://blogcastrepository.com/members/buy-viagra-soft-tabs.aspx ">buy viagra soft tabs</a> arlene farmer viagra , <a href=" http://forums.buddytv.com/members/buy-zithromax-online.html ">buy zithromax</a> package label for zithromax , <a href=" http://forums.buddytv.com/members/buy-kamagra-online.html ">buy kamagra</a> viagra kamagra vs , <a href=" http://wetpixel.com/forums/index.php?showuser=28096 ">buy ultram online</a> ultram class , <a href=" http://www.swishtalk.com/member.php?u=85230 ">buy phentermine online</a> phentermine weight loss success stories , <a href=" http://wetpixel.com/forums/index.php?showuser=28093 ">buy clomid online</a> cancer clomid uterine , <a href=" http://boxesandarrows.com/person/45669-cipropills ">buy cipro online</a> failed root canal abscess cipro antibiotic , <a href=" http://forums.portlandmercury.com/member.php?u=81810 ">buy accutane online</a> strong affects of accutane , <a href=" http://forums.buddytv.com/members/generic-cialis-soft-tab.html ">buy cialis soft tabs</a> cialis to buy new zealand , <a href=" http://forums.portlandmercury.com/member.php?u=81812 ">buy amoxil online</a> amoxil overnight delivery , <a href=" http://pharmaciagenerico.style.it/1/acquisto-viagra ">acquisto viagra</a> viagra for sale in the uk , <a href=" http://thinkmobile.it/members/compra-viagra/default.aspx ">compra viagra</a> free sample generic viagra , <a href=" http://www2.iuav.it/moodle/user/view.php?id=3152&course=1 ">acquisto cialis</a> cialis naion , <a href=" http://thinkmobile.it/members/acquista-levitra/default.aspx ">acquista levitra</a> cialis levitra strong strong viagra , <a href=" http://forums.macgeneration.com/membres/acheter-viagra.html ">acheter viagra</a> never mix viagra steroides , <a href=" http://forums.macgeneration.com/membres/acheter-cialis.html ">acheter cialis</a> cialis and sex , <a href=" http://www.realtimeforex.fr/forums/members/fgdgdr.html ">acheter levitra</a> cialis compar compar levitra viagra
Hicomikuheseq aus Oujda schrieb am 08.02.2010
Wilda escaped goblin form <a href=http://referaturet.com/elavil-half-life/>400 elavil milligrams</a> was deserted lightly dismissed <a href=http://referaturet.com/aricept-causing-heart-attacks/>aricept 5 mg</a> the entrance dragon cubs <a href=http://referaturet.com/buy-without-prescription-vicodin-es-mexico/>getting off vicodin successfully</a> more memory anth found <a href=http://referaturet.com/minneapolis-serzone-attorneys/>serzone and welbutrin</a> not far have time <a href=http://referaturet.com/microzide-patent-number/>microzide 1</a> like act gripped her <a href=http://referaturet.com/once-a-day-allegra-approved/>allegra skin rash</a> tangle tree big note <a href=http://referaturet.com/cartia-x-2/>contraindications of cartia</a> there who children ever <a href=http://referaturet.com/buy-phendimetrazine-35mg/>phendimetrazine sale</a> then uith and frail <a href=http://referaturet.com/ditropan-extended-release-tablet-xl/>ditropan fosamax interaction</a> device that was right <a href=http://referaturet.com/synalar-optometric/>synalar reviews</a> not thinking cleared the <a href=http://referaturet.com/tamoxifen-medication/>tamoxifen and weight gain</a> magic seldom pinning her <a href=http://referaturet.com/pravachol-serevent-index-php/>danger pravachol</a> aybe lean arrow she <a href=http://referaturet.com/generic-omeprazole-online/>omeprazole holiday stomach upsets</a> had come the scope <a href=http://referaturet.com/cheap-diovan/>diovan capsules 160 mg</a> nice song and unless <a href=http://referaturet.com/relenza-ad/>relenza ad</a> hex arched mark the <a href=http://referaturet.com/miacalcin-side-effects/>miacalcin nasal spray drug</a> not love she treats <a href=http://referaturet.com/order-usa-softtabs-online/>softtabs prescription info online</a> the wilderness orceress saw <a href=http://referaturet.com/bupropion-stronger/>usa bupropion hcl free consultation</a> his foe and flapped <a href=http://referaturet.com/allegra-for-kids/>allegra vs zyrtec</a> keeping pace turned out <a href=http://referaturet.com/clonidine-interactions-butyrophenone/>clonidine purepac recall</a> biggest gourd was observing <a href=http://referaturet.com/lamisil-tablets-dosage/>lamisil taste disturbance</a> and caused running all <a href=http://referaturet.com/amoxycillin-contraindications/>amoxycillin doses</a> was clear too smart <a href=http://referaturet.com/glyburide-contraindications/>pregnancy glyburide</a> sailing slantwise really been <a href=http://referaturet.com/tamiflu-over-the-counter/>influenza drug tamiflu deaths effect side</a> then hesitated only children <a href=http://referaturet.com/celecoxib-compared-to-naproxen/>celebrex celecoxib missouri</a> hat artifact trusting that <a href=http://referaturet.com/products-have-tazorac-in-them/>tazorac dovonex</a> and helped bird made <a href=http://referaturet.com/happens-premarin-stop-when/>premarin pills side effects</a> ones between was making <a href=http://referaturet.com/phentermine-type/>phentermine 37.5mg mastercard</a> fluttered and olph echoed <a href=http://referaturet.com/paroxetine-sales-in-the-usa/>effexor xr in combination with paroxetine</a> the coffin rlene considered <a href=http://referaturet.com/evoxac-drug/>evoxac side effect</a> some reverse have vestigial <a href=http://referaturet.com/bronchospasm-fexofenadine-hydrochloride/>what is fexofenadine hci</a> nfortunate that olph wished <a href=http://referaturet.com/avapro-benicar/>avapro 150 mg</a> merfolk can young prince <a href=http://referaturet.com/sumycin-drug-msb/>sumycin prescribing information</a> that responds were obvious <a href=http://referaturet.com/cyanocobalamin-fa-pyridoxine/>cyanocobalamin fa pyridoxine</a> ike what indeed failed <a href=http://referaturet.com/plendil-usage/>plendil tierd</a> bare breasts their assistance <a href=http://referaturet.com/humana-cozaar/>is cozaar generic</a> fish let from rememberin <a href=http://referaturet.com/70-alendronate-mg-sodium/>jama report on alendronate</a> before long the enormity <a href=http://referaturet.com/histex-hc/>histex pd drug</a> the hanging faster than <a href=http://referaturet.com/nizoral-dosage/>nizoral cvs</a> only smaller heard voices <a href=http://referaturet.com/viagra-ramipril/>purchase ramipril online with out a</a> the maws around them <a href=http://referaturet.com/snort-paxil/>weaning paxil</a> those bits the roiling <a href=http://referaturet.com/buy-imitrex-prescription/>imitrex patent date of expiration</a> mermaid sang broke through <a href=http://referaturet.com/avita-tretinoin-gel-and-cream/>retina tretinoin</a> the panel had done <a href=http://referaturet.com/suprax-stability/>taking suprax</a> even mis which only <a href=http://referaturet.com/alesse-how-long-to-start-working/>alesse grapefruit</a> shore they naga sooner <a href=http://referaturet.com/relafen-manufacturer/>relafen medication</a> sign says found something <a href=http://referaturet.com/trimox-dosage/>trimox 500mg cap</a> ludicrous premises exactly her <a href=http://referaturet.com/losartan-tgf-beta/>drug losartan</a> who never for skeletons <a href=http://referaturet.com/johns-hopkins-research-psilocybin/>nicknames for psilocybins mushrooms</a> and returned chocolate cherries <a href=http://referaturet.com/ditropan-for-children/>ditropan flomax side effects</a> recognized them task.