Saturday 15 February 2014

A simple chatroom

Here, as I previously mentioned, I am going to talk about a simple chatroom that I made using MySQL, PHP, and JavaScript.
b-chat
Note that here I am not actually going to talk about 'how' to make a chatroom, nor will I present any code. I am just going to talk about it in a very high level manner. I try to explain things as much as I can, but if there are things that are not very understandable, I am pretty sure that you can find out about them just by a few searches in the internet. I am also quite sure that if you do enough research, based my explanations you can make your own chatroom! So let' begin:

First of all,  once you enter the website there is a JavaScript 'alert' message that asks for your name. Once you enter your name, it is stored in a cookie (cookie is just a file stored on your computer that holds some information) on your own computer.

Second, each time you send a message, your message is stored in a mySQL remote database. So are the messages sent by the person you are chatting with. Now the issue is: How can you get to see the messages sent by you friend? Here was my solution: Do you remember in the last topics I talked about AJAX requests? (Just to remind you, AJAX is a method of communication with the server without the need to refresh the whole page).

There is a client-sided JavaScript code that sends a request to a PHP script on the server every 3 seconds and using AJAX method (Therefore the webpage will not be refreshed each time). Now, the request that is sent to the PHP script includes some information such as the name of the person who has sent that AJAX request (The name of the person is read from the cookie). The the PHP sends back all messages store in the database EXCEPT the ones that were by the sender of that request. This way you can get too see your friends messages as well.

Note that these were just very brief descriptions of the procedure ... If I want to explain everything about this it will probably take me at least 5-6 blog posts. But since I know it is going to be boring for some of you, I will not be doing it here :)

In the next topic I am going to talk about another application that I made with JavaScript. Namely myChecklist that you can use to schedule your future plans. This is an application that runs offline (no internet connection needed for it). And finally, if you are using Google Chrome, you can install it before I get to talk about it in my next post.


Image Source: <Chrome Web Store - myChecklist . Available in: https://lh3.googleusercontent.com/g0G64-L84uNn8mDfpqA2aJcH5_HtAxWT_pQ69QV2UFtELGVRI09fsg0N6cDP3Zr2qHKp0K20Mw=s640-h400-e365-rw>


No comments:

Post a Comment