Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen der Seite angezeigt.

Link zu der Vergleichsansicht

Beide Seiten, vorherige Überarbeitung Vorherige Überarbeitung
Nächste Überarbeitung
Vorherige Überarbeitung
talit:web:webapps:polling [2026-09-10 19:00] – hoftalit:web:webapps:polling [2026-09-21 17:05] (aktuell) – [Long-Polling] hof
Zeile 11: Zeile 11:
 } }
  
-async function handleFetch(grid, status, url) {+async function handleFetch(grid, url) {
   let response = await fetch(url)   let response = await fetch(url)
   if (response.ok) {   if (response.ok) {
Zeile 17: Zeile 17:
     // Update the HTML view.     // Update the HTML view.
     updateHtml(grid, game)     updateHtml(grid, game)
-    // Update game status area to reflect winner / tie 
-    updateStatus(status, game) 
   }   }
   // POLLING: Falls wir nicht am Zug sind, holen wir uns nach 500ms    // POLLING: Falls wir nicht am Zug sind, holen wir uns nach 500ms 
Zeile 25: Zeile 23:
   if (game.state == "waiting" || game.state == "playing" && !game.myturn) {   if (game.state == "waiting" || game.state == "playing" && !game.myturn) {
     await wait(500)     await wait(500)
-    await handleFetch(grid, status, "game")+    await handleFetch(grid, "game")
   }   }
 } }
 </code> </code>
  
 +Beobachte den Netzwerkverkehr dieser Lösung in den _Developer Tools_!
 ### Long-Polling ### Long-Polling
 Mit der obigen Lösung fragt jeder Client zweimal pro Sekunde nach einem Update. Polling hat zwei Nachteile: Mit der obigen Lösung fragt jeder Client zweimal pro Sekunde nach einem Update. Polling hat zwei Nachteile:
Zeile 112: Zeile 111:
  
 <code javascript connect4_client.js> <code javascript connect4_client.js>
-async function handleFetch(grid, status, url) {+async function handleFetch(grid, url) {
   let response = await fetch(url)   let response = await fetch(url)
   if (response.ok) {   if (response.ok) {
Zeile 118: Zeile 117:
     // Update the HTML view.     // Update the HTML view.
     updateHtml(grid, game)     updateHtml(grid, game)
-    // Update game status area to reflect winner / tie 
-    updateStatus(status, game) 
   }   }
   if (!response.ok) {   if (!response.ok) {
Zeile 125: Zeile 122:
   }   }
   if (!response.ok || game.state == "waiting" || game.state == "playing" && !game.myturn) {   if (!response.ok || game.state == "waiting" || game.state == "playing" && !game.myturn) {
-    await handleFetch(grid, status, `longpoll`)  // longpoll to wait for state change+    await handleFetch(grid, `longpoll`)  // longpoll to wait for state change
   }   }
 } }
  • talit/web/webapps/polling.1789059613.txt.gz
  • Zuletzt geändert: 2026-09-10 19:00
  • von hof