Friday, September 25, 2015

How to Quickly Build a Chat App with Ratchet

In this tutorial, we’ll be taking a look at Ratchet, a PHP library for working with WebSockets. Let’s start by defining what WebSockets are. MDN says:

WebSockets is an advanced technology that makes it possible to open an interactive communication session between the user’s browser and a server. With this API, you can send messages to a server and receive event-driven responses without having to poll the server for a reply.

Connected computers image

WebSockets allow us to write applications that can pass data from the browser to the server and vice-versa in real-time.

Setup

First, let’s install Ratchet using Composer:

composer require cboden/ratchet

Building the App

Now we’re ready to build the app. Create a Chat.php file under the class/ChatApp directory. This would be a class under the ChatApp namespace, and it would use use Ratchet’s MessageComponentInterface and ConnectionInterface. The MessageComponentInterface is used as the basic building block for Ratchet applications, while the ConnectionInterface represents the connection to the application.

Continue reading %How to Quickly Build a Chat App with Ratchet%


by Wern Ancheta via SitePoint

No comments:

Post a Comment