Recommend this page to a friend! |
Classes of Ahmad Mustapha | ReactPHP Chat Client | README.md | Download |
|
DownloadReactPHP Live ChatA PHP-based live chat written on top of Ratchet - (PHP library for asynchronously serving WebSockets). <br/> This program and Ratchet relied on Event-Loop provided by ReactPHP. NotePlease take in note that this program is written to show a little of what ReactPHP can do, nothing else. <br/> You are not encouraged to used this program publicly. Features
InstallationMake sure that you have composer installed Composer. If you don't have Composer run the below command
Clone the repository
Navigate to the directory
<br/>Then install the required dependencies using composer <br/>
ConfigurationRename ".env.example" file to ".env"<br/> To change default configurations, edit ".env" file. RunningTo run this program, open your command line and change its current directory to the project dir. Run the below command.
Then open the project in your browser using(http://localhost:9000). How it works(Http)browser -> server -> router -> controller -> response -> browser.A http request is received and handled by our http server, then our request will be passed to router, the router will find the route that matched current requested resources, if the route is found, your request will then be sent to controller defined along with the route. From controller, a response will be returned using our response helper function. How it works(Socket)ws.send() -> ratchet -> colis -> listener -> response -> browser.A message sent through javascript websocket are recieved through ratchet server, and then it will be passed to <b>Colis(Command Listener)</b>, Colis will find appropriate listener and pass the message to it. Think of <b>Colis</b> as something similar to <b>Symfony/Laravel Router</b>. Its syntactically designed to look similar to Laravel's Router. Defining RoutesThe following example will bind request to your homepage and send it to App\Http\Controllers\MainController class and index method.
Your controller syntax will be like
Listening CommandThe following code will listen to "public.chat.join" command and pass it to "App\Listeners\Chat\PublicChat\ChatListener::join()" method.
Sending MessageA helper for sending messages has been provided
Command/Message SyntaxExpected message syntax, if you are sending message/command to system it should have below syntax:
Two things to take note of, <b>command & time</b> attributes are neccessary. Expected response syntax:
Packages usedSpecial Thanks
Feel free to report any issuesYour contributions are welcomed. |