📘 CodingMarble Learn

Software and Simple Networked Apps: Chat and Email

Software is the set of instructions that makes hardware useful. A networked app such as chat or email has a client (on your device) and a server (always on, far away). They pass addressed messages; the server forwards them at once (chat) or keeps them in a mailbox until you come online (email).

🎬 Step-by-step story

  1. Software means instructions for the computer. It runs in layers: hardware at the bottom, the operating system (OS) in the middle, and your app on top. The OS looks after the hardware so the app can do one job.
  2. A networked app has two parts. The client is the app on your phone, the part you see and tap. The server is a program on a computer far away that is always switched on. They talk by sending messages over the network.
  3. Ana types 'Hi!' and presses send. Her client puts an address on the message: 'To: Ben'. It sends this packet towards the server.
  4. The server reads the address and passes the message on to Ben's client. Ben's screen shows it at once. This is how chat works: the server forwards it straight away.
  5. Now Ben is offline, his screen is dark. The server keeps Ana's message in Ben's mailbox. When Ben comes online, the server gives it to him. This 'store and forward' is how email works.
  6. Your turn. Send a message from Ana or from Ben. Switch someone offline and online. Watch where the message goes each time.

Tip: drag the 3D scene to turn it. Use two fingers to zoom.

🤔 Common doubts, cleared

Is software just the apps I use?

No. The operating system is software too, and it sits between the hardware and the apps. Watch the layers in the 3D.

Why do we need a server? Can't two phones talk directly?

They can in some cases, but phones go offline, change their addresses and sit behind firewalls. A server has a fixed address and is always on, so it is a reliable meeting point.

What is written on the packet?

At least who it is from, who it is to, and the text. The to-address is what the server reads to forward it.

Does the server read my chat?

It must read the address. If the app uses end-to-end encryption, the server cannot read the text. Otherwise the company could read it, so choose apps carefully.

What if the other person is offline?

The server keeps the message in a mailbox and delivers it when they come online. Watch Ben's dark screen and the envelope in the box.

Can I build this myself?

Yes. Many languages (Python, JavaScript) have simple tools for sending messages between two programs. Start with a two-client chat on your own computer.

What is software and what does it do?

Hardware is the parts you can touch: screen, memory, processor. Software is the instructions that tell the hardware what to do. Without software the hardware does nothing.

Software works in layers:

In an information system, software takes the data in, processes it, stores it and shows the result. A chat app takes in your text, adds an address, sends it, and shows the reply.

Clients and servers

Most apps that use the Internet have two programs.

The client runs on your phone or computer. It shows the screen, takes your taps and sends requests.

The server runs on a powerful computer that stays on all day. It receives requests from many clients, does the work, keeps the data and sends answers back.

Why not let two phones talk directly? Phones go offline, change their addresses and sit behind firewalls. A server has a fixed address that everyone can find, so it acts as the meeting place.

How a chat app works

1. Ana types a message. The client builds a small packet: who it is from, who it is to, and the text. For example: MSG|ana|ben|Hi!

2. The client sends the packet over the network to the server's address and port.

3. The server reads the 'to' field, looks up Ben's open connection, and forwards the packet.

4. Ben's client reads the packet and shows the text.

The rules for how messages look and what to do with them are called a protocol. Both programs must follow the same protocol, just like two people must speak the same language.

How an email-style app works

Email uses store and forward. Your mail client sends the message to your mail server. That server passes it to the receiver's mail server, which puts it in the receiver's mailbox. It stays there until the receiver opens the mail app and fetches it. So the receiver does not need to be online when you send.

The common rules are called SMTP (for sending) and IMAP or POP3 (for fetching). Many chat apps also keep messages for offline friends, so they use the same idea.

Steps to develop a simple chat or email app

  1. Plan: What can users do? Send a message, see messages, log in.
  2. Design the messages (protocol): choose the fields, such as MSG|from|to|text.
  3. Write the server: wait for clients, read the address, forward or store the message.
  4. Write the client: a screen with a text box and send button that talks to the server.
  5. Test with two clients: online and offline cases, empty messages, very long messages.
  6. Make it safe: ask users to log in, check every message the server receives, and use encryption so that others cannot read it on the way.

A tiny server in plain steps:

repeat forever:
  wait for a packet
  read the 'to' name
  if that person is online: send the packet to them
  else: put the packet in their mailbox

Try it at home

Play 'server' with two friends in different rooms. Friend A writes a note 'To: B' and gives it to you. You read the address and walk it to B. If B is out of the room, put the note in a box with B's name and hand it over when B returns. You have just done chat and email by hand!

Key formulas and definitions

Worked examples

1. You open a school portal on your phone. Which part is the client and which is the server?

The portal app or browser on your phone is the client: it shows pages and sends your requests. The computer at the school or company that holds the data and answers is the server.

2. Write a message in the form MSG|from|to|text for Riya telling Aman 'Ready?'. What does the server read to know where to send it?

MSG|riya|aman|Ready? The server reads the 'to' field, which is aman, and forwards the packet to Aman's client.

3. Meera sends an email to Sam, who has his phone switched off. Explain what happens.

Meera's client sends the email to her mail server. It passes the email to Sam's mail server, which puts it in Sam's mailbox. When Sam switches on his phone and opens the mail app, the client fetches the email from the mailbox.

4. A chat server gets 120 messages every minute. How many is that per second, and is it enough to say the server must be always on?

120 ÷ 60 = 2 messages per second. Messages can arrive at any second of the day, so yes, the server must be always on.

5. Put the work of the server in a chat app in order: forward the message, read the address, receive the packet, check Ben is online.

Receive the packet → read the address → check that Ben is online → forward the message. If Ben is offline, the server stores it in his mailbox instead.

Common mistakes

Practice quiz

1. Which software manages the hardware and runs apps?
2. In a chat app, the program that stays always on and forwards messages is the:
3. An email for an offline person waits in their:
4. The agreed rules for how messages look and are handled are called a:
5. What does the server read to decide where to send a message?

Practice: answer these yourself

Type or choose your answer, then press Check. Use a hint if you are stuck; the full solution appears after you answer.

Frequently asked questions

What is the difference between a client and a server?

The client runs on your device and asks for things; the server runs on another computer that is always on and answers many clients.

How does a chat app send messages so fast?

The client keeps an open connection to the server. The message is sent as a small packet with an address, and the server forwards it straight to the other person's open connection.

Do I need to be a programmer to understand this?

No. You only need to know the roles: the client shows and sends, the server forwards or stores, and the protocol says how messages look. Building one comes later with a programming language.

Where this is taught

China高一Comp.2 Ch.3 Infrastructure

Learn first

Learn next

Related lessons

All Computer Science lessons