0
0
Computer-networksConceptBeginner · 3 min read

What Is a Computer Network: Definition and Examples

A computer network is a group of two or more computers connected to share data and resources. It allows devices to communicate and exchange information easily over wired or wireless links.
⚙️

How It Works

A computer network works like a group of friends passing notes to each other. Each computer or device is like a friend who can send and receive messages. These messages travel through cables or wireless signals, similar to how notes travel through the air or along a string.

When one device wants to share information, it breaks the data into small pieces called packets. These packets travel through the network to reach the correct device. The network uses rules called protocols to make sure the packets arrive safely and in order.

💻

Example

This simple Python example shows how two computers can communicate over a network using sockets. One acts as a server waiting for messages, and the other as a client sending a message.

python
import socket

# Server code
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_socket.bind(('localhost', 65432))
server_socket.listen()
print('Server is listening...')
conn, addr = server_socket.accept()
with conn:
    print('Connected by', addr)
    data = conn.recv(1024)
    if data:
        print('Received:', data.decode())

# Client code
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client_socket.connect(('localhost', 65432))
client_socket.sendall(b'Hello from client')
client_socket.close()
Output
Server is listening... Connected by ('127.0.0.1', <port>) Received: Hello from client
🎯

When to Use

Computer networks are used whenever devices need to share information or resources. For example, in homes, networks connect phones, computers, and smart devices to the internet. In offices, networks allow employees to share files and printers easily.

Networks are also essential for online services like email, video calls, and websites. Without networks, devices would work alone and could not communicate or share data efficiently.

Key Points

  • A computer network connects multiple devices to share data and resources.
  • Data travels in small packets following rules called protocols.
  • Networks can be wired (cables) or wireless (Wi-Fi).
  • They enable communication, file sharing, and internet access.

Key Takeaways

A computer network links devices to share data and resources.
Data is sent in packets using protocols to ensure proper delivery.
Networks can be wired or wireless depending on the connection type.
They are essential for communication, internet access, and resource sharing.
Understanding networks helps in setting up and troubleshooting device connections.