Skip to Content
ハンズオンNode.js
book

ハンズオンNode.js

by 今村 謙士
November 2020
Beginner to intermediate
536 pages
6h 42m
Japanese
O'Reilly Japan, Inc.
Content preview from ハンズオンNode.js

6章リアルタイムWebアプリケーション

Webアプリケーションにおけるクライアント・サーバ間のコミュニケーションは、典型的にはクライアントが送信したリクエストに対しサーバがレスポンスを返すというものです。このパターンでは、クライアントがサーバの最新情報を取得するために、サーバにリクエストを送る必要があります。「5章 HTTPサーバとHTTPクライアント」で作成したユニバーサルWebアプリケーションでは、ブラウザでページを開いた直後はその時点での最新のToDo一覧が表示されます。しかしページを開いたまま10分経過したら、その情報は古くなっている可能性があります。新しいToDoが追加されているかもしれませんし、未完了だったToDoが完了しているかもしれません。古い情報を元に作業していたら、処理すべきタスクを放置したまま完了したタスクを無駄に繰り返してしまいかねません。このような事態を避けるには、ブラウザを定期的にリロードして常に最新のToDo一覧を確認する必要があります。

これに対し、ブラウザリロードなどのユーザー操作によることなく、クライアントサイドにサーバの最新情報を同期させるような仕組みを持つWebアプリケーションをリアルタイムWebアプリケーションと呼びます。本章では複数のリアルタイムWebアプリケーションの実装方式を学び、その一部を使って実際にToDo管理アプリケーションをリアルタイム化します。

6.1 ポーリング

ポーリングはリアルタイムWebアプリケーションを実装するための最もシンプルな手段です。クライアントはユーザー操作をトリガーとしないWeb APIの呼び出しを一定間隔で繰り返し、定期的に状態をサーバと同期します(図6-1)。

図6-1 ポーリング

サーバサイドでは特別な実装は必要なく、たとえば「5章 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

リーンエンタープライズ ―イノベーションを実現する創発的な組織づくり

リーンエンタープライズ ―イノベーションを実現する創発的な組織づくり

Jez Humble, Joanne Molesky, Barry O'Reilly, 角 征典, 笹井 崇司, Eric Ries
レガシーコードからの脱却 ―ソフトウェアの寿命を延ばし価値を高める9つのプラクティス

レガシーコードからの脱却 ―ソフトウェアの寿命を延ばし価値を高める9つのプラクティス

David Scott Bernstein, 吉羽 龍太郎, 永瀬 美穂, 原田 騎郎, 有野 雅士

Publisher Resources

ISBN: 9784873119236Other