WebSockets!和克里斯·博登



注意:這應視為系列的第2部分。演講「反應:事件驅動的編程」涵蓋了理解WebSockets基礎的核心概念。

現在有了非同步編程,我們將介紹一個非常有趣且實用的網路編程應用程序:WebSockets! WebSockets是一種允許Web瀏覽器與伺服器之間進行雙向實時通信的技術。現在是2013年,讓我們已經在網路上推送通知了!

WebSocket是HTML5傘下引入的一項功能,但對開發人員而言,實現中的大部分(也是最難的部分)都是在伺服器端完成的。

您將了解什麼是WebSocket,它們是如何工作的,它們的缺點和陷阱,以及如何(主要)克服它們。在了解了一些基礎知識之後,將向您介紹Ratchet,PHP WebSocket庫,以及如何將PHP同步堆棧體系結構與另一種語言/實用程序結合起來,以便在應用程序中使用WebSockets。

最後,我們將回到瀏覽器並討論使用情況,瀏覽器問題/修復程序和消息傳遞協議。 。

6 comments
  1. for creating private chat (3 users A, B, C and each of them want to chat private), what we need to do 1) create different routes for each user (like you created /chat)
    2) handle it using some other technique like session etc

  2. I have to create a little AJAX chat in my web application and I'm dealing with problem of real-time communication between javascript client and PHP server. I want my js client to be able to catch new messages from the server as quick as possible. My first idea was to create AJAX request for example each 5 sec. to see whether there are new messages. However, I'm not sure what happens if my application use for example 1000 people, it must be huge load to Apache httpd. I also know about technique called 'long-polling' request, but when I tried that locally on my server, I've completely shooted down my Apache (I've read sth about problems with apache and long-polling). The next way I know about is WebSocket. However, is it true that I have to be able to open port on webserver to use it? Because on regular web hosting, I thing it's not possible and I cant change any Apache/PHP settings on my hosting. Do you have any suggestions how to solve it?

Comments are closed.