Web Video Box Office
Image Gallery
Realistic Skin Rendering in WebGL
A rainbow cloud shimmers over Ethiopia
X-ray reveals hidden Goya painting
Realistic Skin Rendering in WebGL
A rainbow cloud shimmers over Ethiopia
X-ray reveals hidden Goya painting
Welcome to episode 1 of “How It May Work”, a web series where we try to make educated guesses on how software applications around us work. The aim of this series is to provide food for thought for budding programmers and help them get started on DIY projects. In this episode, we are going to talk about chat clients.
We’ve all used chat clients since the early days of the internet. They were the precursors of today’s social networks and have still managed to survive in their original form. So let’s put our thinking hats on and begin our study. A typical chat client:
Let’s start with #1. We need to maintain a list of friends. Let’s start simple and keep it as file on our computer. The file will be a list of email addresses.
| Email Address |
| Email Address | Password |
Note: Real databases should never store passwords. They always use a “one way hash function” to convert the password into some alphanumeric gibberish. Since this is a “one-way” process, passwords cannot be revealed even when the database is compromised.
Question 1: Why do we need to log in anyways?
Now, let’s tackle the real problem. We want to be able to send a private message to a user in our friend list. To be able to send a message to our friend’s computer over the internet, we will need his “IP Address”. Now we have hit a roadblock. We don’t have this information anywhere. Our friend list file contains only email addresses. To solve this problem we can save the IP address of a user on the server and download it to our computer, when he is added to the friend list.
To achieve this, we will need the server to remember the IP address. So let’s update Table 2.0 to reflect this:
| Email Address | Password | IP Address |
There ! Problem solved. In order to make this work we will now need to update Table 1.
| Email Address | IP Address |
Now we can look up the IP address from this file and use that to send a private message to his computer. But what if we want to chat from another computer? Without the file, the chat client won’t know who your friends are. So definitely this approach of “statically” storing IP addresses won’t work. We need an approach that is “dynamic” where the data is updated whenever the user changes location. We need a data-store that is always online and always kept up-to-date. And the chat server is the ideal candidate for such a data store.
Let’s add another table to the server, from where we can look up the friend list given any user.
| User Email Address | Friend Email Address |
Table 3.0 has a “one-to-many” relationship between a user’s email address and his friend’s email address. This means, if there are N users with M friends each, then the table will have N x M rows.
We now have all the pieces needed to create a robust chat network. Let’s review our algorithm.
That’s all for this episode. Until next time, I will leave you with some questions to ponder about.
Another month, another episode of Links Around the World, but this time with a twist. Enjoy LATW in an all-new magazine-app-ish format.
Light bulb that’s been on since 1901
Data-driven enhancement of facial attractiveness
Sitting is killing you
25 Futuristic Abandoned Yugoslavian Monuments
Simon Schubert creates complex scenes in paper using creases
1. Liquefaction from the Sendai earthquake
2. World’s biggest wholes
3. Quadrocopters juggle balls cooperatively
4. RED Epic Footage: Rise of the Valkyries
5. Zdenek Kalal’s object tracking algorithm learns on the fly
6. How Can I Take Better Photos in Low Light?
7. Why Questions
8. Music synthesized from the Game of Life
Fifty Ugliest Cars of the Past 50 Years
Gravity satellite yields ‘Potato Earth’ view
Fractal Lab lets you create 3D WebGL fractals that you can explore
Computing