How I build a chat system in highschool

Gautham Santhosh
5 min readJun 20, 2020

--

When I was in high school (SFS Ettumanoor), we had this computer lab period. It was one of the most boring, no internet, sitting solving boring C++ questions.

The nerd in me stood among the few in this brave but short period of time, for we had found something that understood us more than humans — code. While others stood there crying in agony about the horrors of not even understanding the question.

🙆‍♀️ The cause — A brilliant accident.

The teacher had no idea, she had the networking on, so windows have this concept of shared files. So in this huge folder, there were names of computers, and people could open the file and write anything, and then others can read it.

Shared folders on windows 10, back then it was windows 7. Credits: mywindowshub.com

It’s google docs or cloud or whatever you call it now. Well, there is no cloud it is someone else’s computer.

📝 The first step — Cheat the system

At the end of every class, we had to solve problems and send them to the teacher who will check it. The shared folder started becoming this place to cheat. Sending each other code.

🤔 The second step — We can do much more than cheat!

One day, I saw this commotion as people started talking to each other. If Adam had a shared folder, then Anna would make a file named anna.txt and then start editing it. And then they will save it. They started making these private chat files.

— — — — anna.txt — —Hey, Adam what’s up

Adam would open the file, read it and then reply and then save it.

— — — anna.txt — — Hey, Adam what’s up
Nothing much

Well, people were really bored.

💪 Evolution of messaging and overwritten docs

Then Anna would reply and it went on. But then came the first problem. Adam wrote without waiting for a reply and Anna’s file overwrote his file.

So Anna wrote

— — — anna.txt — —Hey, Adam what’s up
Nothing much
How was your weekend

Adam wrote

— — — anna.txt — —Hey, Adam what’s up
Nothing much
Did you watch the new Netflix show -- IDK kill me, i know no one herd of Neflix back them (IM SO OLD)

But this was crap, then the last person to save the doc overwrote the last one. So only one can only send messages at a time, so they came up with the simplest way.

Adam after sending a message, waves or winks to Anna. She would then open the message and read it. Then write her message and then signal adam. This was slow at first but then they got fast at it. Let’s call this the signal from now on.

📚 We need structure — Ordering things

So this became huge a person started having 10’s of chats with multiple people and often found it hard to read what someone else wrote. Who wrote what. Simple solution, it became to.

— — — anna.txt — —Anna: Hey, Adam what’s up.      - tell adam via signal
Adam: Nothing much. - tell anna via signal
Anna: How was your weekend - tell adam via signal

😢 Chaos — End of system

So this got popular, everyone started using this.

But it was public as well. Everyone could read others' chats. I guess the next step was to put passwords to files.

But all these waving and sending signals after typing a message made a loud noise. The teacher got curious and figured out what was happening and shut the network down. It was all over.

We were back to pull out more of our ever-dwindling hair and bored out of the never-ending lab.

🤯 Connecting the dots — writing code

We had to submit a final project for the year. I thought why not build this system with code. One of the partners got excited, other one didn’t even care.

So I opened my C++ book, okay first page how to read a file. The code read from a file and then wrote to a file and saved the file after someone enters a line.

username = input()
while True:
chat_text = input()
if chat_text:
file.write(username + chat_text)

Something like this, highly oversimplified.

But this method is better since the reading and writing will be done in such a short period of time, no one needs to signal the other person. No more chaos.

🚀 Just make it work!

But the problem was where should we keep the file. We couldn’t figure out how to access the low-level network of networks and go and write in each user's system. I had no idea how to even say this at that time. I was a kid.

So instead we took one device and then shared a folder in that device and everyone wrote chat. This was done to make everything simple. But this was a good trade-off. I just had to make a file for each and every person with another person. So the file name will be the name of the two people.

from_username = input()
to_username = input()
file = open_file(name_of_file = from_username + to_username)
if file doesnt exist:
file = new_file(name_of_file = from_username + to_username)

FYI: You need to check both combinations, I removed a lot of things for the sake of simplicity.

🙏🏻 Ending notes

Internally this is how most things work. The internet chat systems Whatsapp or Instagram DM’s all of it works like this internally. But highly oversimplified.

But this has all the modern problems we face, like the one who owns the final computer, the one where we store all the chat can read it anytime they want. Well, we know many companies have done that already and send targetted ads. This can be solved partially anyway.

But there was something about this that stricken with me forever, the ability to see real-world events and make them into code. I think it’s a valuable skill and it can definitely change a lot of things.

Go out there and code something.

This happened 6–7 years ago and I barely remember most of the detail, if I got something wrong please forgive me

Thank you for reading 😅. If you like the Article give it a clap 👏.

If you wish to have a chat, DM me at https://twitter.com/gauthamzzz. My website is gauthamsanthosh.com.

--

--