5 – Modelling a Network

📖 Learning Objectives

Develop the Network and Communications, Programming and Development learning strands:

  • How computers, IP addresses, routers and packets are used to send data between devices
  • What a variable is and how we can use them in Scratch
  • How to use the broadcast block in Scratch
  • How to use loops (iteration) in Scratch
  • How to use the ask and answer blocks in Scratch to receive user input in Scratch
💬 Key Vocabulary

  • model
  • communication
  • iteration
  • loops
  • variable
  • broadcast block

📝 Getting Started

  • Go to the Scratch website and create a new project.
  • Call the project “Virtual Network”.
  • Delete the cat sprite.
  • We’re going to need three sprites to start with.
    • A computer
    • A router
    • A packet
  • Save the below images and then upload them both to Scratch.
  • To create the packet, use the paint tool in Scratch to create a small circle to represent a packet.
  • We’ll name the sprite for the computer with an IP address.
  • On most home networks the IP address will fall into the range of 192.168.1.1 up to 192.168.1.254. We’ll give our computer the first IP address, so call it 192.168.1.1
  • We’ll name the Router router and the Packet packet.
  • Here’s a screenshot of what the sprites should like so far:
  • Next we’ll need three variable, to represent the data the packet is going to contain.
  • Create a variable called source.
  • Create a variable called destination.
  • Create a variable called data.

📝 Scripting the Computer

  • Click on the computer sprite so that you can add scripts to it.
  • The script we need is very simple.
  • When the sprite is clicked, the variable source needs to be set to the name of the sprite (in this case 192.168.1.1), and a message needs to be broadcast called Create Packet)
When this sprite clicked
Set source to 192.168.1.1
Broadcast Create Packet

Try It

  • We’ll need more than one Computer on our network.
  • Duplicate the computer a few times (5 should be enough computers, but you can have more or less if you like)
  • Rename each one so that it has a unique IP.
  • Alter the script of each one so that it set’s the variable source to the IP of the computer.

📝 Scripting the Packet

  • The packet script is a little more complicated.
  • The first thing we want to happen, is for the packet to appear on the computer that has been clicked.
  • Next the packet needs to be provided with some information. The variable source already contains the sender’s IP, but the packet needs to know where it is going and what data it should carry.
  • Now get the packet to ask for a message and save the user’s input in the variable data.
  • For the next part we’ll need a loop.
  • We’ll use a Repeat until loop to get the packet to move towards the router, until it touches it.
  • Once the packet has reached the router, it’ll need to move off towards the computer that is currently stored in the variable destination
  • Try to use another Repeat until loop to do this.
  • Finally when the packet arrives at it’s destination, it can say the message that is stored in data for a couple of seconds and then the script can stop.

📝 Checking it works

Run your code, your finished project should look like this:

In this lesson, you…

  • Researched and wrote about the four main concepts in this topic, the Internet, the World Wide Web, Search Engines and Web Browsers.

Next lesson, you will…

  • Explore the technical side of the internet by looking at Domain Names, IP addresses and DNS.

🏅 Badge it

🥈 Silver Badge

  • Upload a screenshot of your code as well as the core parts of it running:
  • Asking for the destination
  • Asking for the message
  • The packet reaching the destination and saying the message
🥇 Gold Badge

  • Alter your network model so that it includes a DNS look-up.
  • The sending computer should ask for a name to send to the packet to.
  • The IP address should then be searched for from a couple of lists.
  • The packet can then be sent to the looked up IP address.