TCP/IP & Internet Protocols
الطبقات، البروتوكولات، والبنية التحتية للإنترنت
التحويل بين الأجهزة على الإنترنت بيتم عبر 4 طبقات، كل طبقة ليها مهمة محددة:
بيكسّر الرسالة لـ TCP Segments ويبعتها، وفي الجهة التانية يرجّعها تاني.
Communication is "end-to-end" — بيتأكد إن الـ packets وصلت بالترتيب وبدون errors.
بيديك عنوان رقمي (IP Address) لكل جهاز على الشبكة.
بيعمل Routing يعني بيحدد المسار من المصدر للوجهة عبر الإنترنت.
TCP + IP = Virtual connection بين source وdestination.
Foundation of the World Wide Web!
بينقل web pages ومحتوى من الـ web server للـ web client (browser).
بروتوكول إرسال الإيميلات! يبعت البيانات لعنوان إيميل تاني.
Application Layer يشتغل على Port 25
الـ Port هو endpoint خاص بـ application معينة على الـ server. ده بيخلي في applications كتير تشتغل على نفس الجهاز.
| Service | Port | Protocol |
|---|---|---|
| HTTP (Web Server) | 80 | TCP |
| HTTPS (Secure Web) | 443 | TCP (TLS) |
| SMTP (Email Sending) | 25 | TCP |
| POP3 (Personal Mail Box) | 110 | TCP |
| FTP (File Transfer) | 21 | TCP |
HTTP Fundamentals
Resources · Request · Response · Caching · Cookies · Security
كل resource على الإنترنت ليه عنوان URL فريد. الـ URL بيتكون من أجزاء:
Example 1:
Example 2:
Absolute:
<a href="http://www.dr-chuck.com/page2.htm"> — عنوان كامل يودي لأي مكانRelative:
<a href="page2.html"> — ملف في نفس الـ folder🔼 HTTP Request Message
The client sends an HTTP request → server sends back an HTTP response. They're two different message types.
[method] [URL] [version]
[headers]
[body — optional, only in POST/PUT]
GET http://www.google.com HTTP/1.1
Host: www.google.com
User-Agent: Mozilla/5.0 Chrome/120
Accept: text/html
| Method | What it does |
|---|---|
GET | Read data — بيجيب data. Body فاضي! |
POST | Insert data — يضيف data جديدة في الـ body |
PUT/PATCH | Update data — يعدّل data موجودة |
DELETE | Delete data — يحذف |
| Header | المعنى | مثال |
|---|---|---|
Referer | الـ URL اللي منه جيت (اللي كليكت عليه) | https://google.com |
User-Agent | معلومات عن الـ browser/software اللي بيبعت الـ request | Mozilla/5.0 Chrome/120 |
Accept | نوع الـ content اللي الـ client عايز يستقبله | text/html |
Accept-Language | اللغة اللي بيفضلها المستخدم | ar, en-US |
Cookie | بيانات الـ cookie اللي الـ server حطها قبل كده | sessionid=abc123 |
If-Modified-Since | للـ Caching — آخر وقت جبت فيه الـ resource | Wed, 25 Jan 2012 |
لما عندك form وتبعتها بـ POST، البيانات بتتبعت في الـ body مش في الـ URL:
<form action="/account/create"
method="POST">
<input name="firstName" />
<input name="lastName" />
<input type="submit" />
</form>
POST /account/create HTTP/1.1
Host: server.com
firstName=Mario&lastName=Cardinal
🔽 HTTP Response Message
[version] [status code] [reason]
[headers]
[body — the actual content]
HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
Content-Length: 17151
Date: Sat, 14 Jan 2012 04:00:08 GMT
<html>...page content...</html>
| Code | Meaning | اللي لازم تعرفه |
|---|---|---|
| 200 OK | Success! طلبك اتنفذ | ✅ نجح كل حاجة |
| 201 Created | Resource created successfully | ✅ تم الإنشاء |
| 204 No Content | Success but no content to return | ✅ نجح بدون محتوى |
| 301 Moved Permanently | Resource moved to new URL | 🔀 تحويل دايم |
| 304 Not Modified | Use cached version — ما اتغيرش | 💾 استخدم الـ cache |
| 400 Bad Request | Malformed request من الـ client | ❌ الـ request غلط |
| 401 Unauthorized | Need to authenticate first | 🔑 محتاج تسجل دخول |
| 403 Forbidden | Server reachable, access denied! | 🚫 وصلت للـ server لكن ممنوع |
| 404 Not Found | Resource doesn't exist | 🔍 مش موجود |
| 500 Internal Server Error | Server crashed/bug | 💥 خرابة في الـ server |
401 = مش authenticated بعد (لازم تعمل login) — 403 = عملت login بس مش عندك permission
| Header | المعنى |
|---|---|
Content-Type | نوع الـ content (media type) — مثلاً text/html |
Content-Length | حجم الـ body بالـ bytes |
Date | وقت إرسال الـ response |
Expires | التاريخ اللي بعده الـ response بيبقى "قديم" |
Location | للـ redirects — العنوان الجديد |
Server | اسم الـ web server |
Connection | خيارات الـ connection |
📂 Media Types & Caching
الـ server بيبعت مع كل response نوع الـ content اللي بيبعته. ده بيتسمى MIME type.
| MIME Type | نوعه |
|---|---|
text/html | صفحة HTML |
image/jpeg | صورة JPG |
text/xml | ملف XML |
application/json | بيانات JSON |
image/png | صورة PNG |
— Client Request Header:
Accept: text/html, application/xhtml+xml
— Server Response Header:
Content-Type: text/html; charset=utf-8
الـ Caching بيحفظ نسخة من الـ resource عند الـ client علشان ما يحملهاش تاني لو ما اتغيرتش.
Time-based Caching:
Last-Modified: Wed, 25 Jan 2012 17:55:15 GMT
Expires: Sat, 22 Jan 2022 17:55:15 GMT
Cache-Control: max-age=315360000, public
Content-based Caching (ETag):
ETag: "8e5bcd-59f-4b5dfef104d00"
Client asks "did it change?":
— Client:
If-Modified-Since: Wed, 25 Jan 2012 17:55:15 GMT
— Server (if not changed):
HTTP/1.1 304 Not Modified
🍪 Cookies & Security
الـ Cookie هو قطعة بيانات صغيرة الـ server بيبعتها للـ client، والـ client بيبعتها تاني مع كل request.
HTTP/1.1 200 OK
Set-Cookie: fname=Mario&lname=Cardinal;
expires=Monday, 09-July-2012 21:12:00 GMT
domain=.mywebsite.com; path=/; HttpOnly
• Session identification
• User tracking
• Preferences storage
• Often just stores a GUID (unique ID)
• Max size = 4KB فقط!
• بتتبعت مع كل request → زيادة bandwidth
• تعمل مشاكل مع الـ Caching
• Never store sensitive info!
| Type | كيف بيشتغل | Security Level |
|---|---|---|
| Basic Auth | بيبعت username:password مشفرة بـ Base64 (مش encrypted!) | ❌ Insecure |
| Digest Auth | بيستخدم MD5 hashing + nonce بدل ما يبعت الـ password | ⚠️ Better |
| Windows Auth | بيعتمد على Windows/Active Directory protocols | ✅ Secure |
| Form-based | الأكثر شيوعاً! Login form + redirect + cookie | ⚠️ Needs HTTPS |
1. Client requests resource:
GET /demo/ HTTP/1.1
2. Server says: who are you?
HTTP/1.1 401 Unauthorized
WWW-Authenticate: Basic realm="localhost"
3. Client sends credentials:
Authorization: Basic bm86aXdvdWxk...
1. Unauthenticated request:
GET /demo/ HTTP/1.1
2. Redirect to login page:
HTTP/1.1 302 Found
Location: /Login.aspx?ReturnUrl=/demo/
3. After login, set cookie:
Set-Cookie: .ASPXAUTH=9694BAB...
HTTP/1.1 302 Found
Location: /demo/
HTTPS = HTTP over TLS (Transport Layer Security)
بيشفّر كل البيانات المتبادلة بين الـ client والـ server.
في الـ browser:
- URL يبدأ بـ
https:// - 🔒 Lock icon في الـ browser
- Port
443
Authentication = إثبات الهوية (من أنا؟)
Authorization = صلاحيات الوصول (أعمل إيه؟)
403 Forbidden = Server وصلته، بس مش معاك permission
401 Unauthorized = لازم تعمل login الأول
HTTP Quiz — أسئلة حقيقية من الامتحانات
اختبر نفسك على كل اللي اتشرح
[method] [URL] [version]GET /page HTTP/1.1 — Status line: HTTP/1.1 200 OK — الـ HTTP version موجود في الاتنين!HTML — HyperText Markup Language
Structure · Tags · Elements · Forms · HTML5
<!DOCTYPE html>
<html>
<head>
<!-- Metadata: not visible on page -->
<title>Page Title</title>
<meta charset="UTF-8">
<link rel="stylesheet"
href="style.css">
</head>
<body>
<!-- Visible page content -->
<h1>Hello World</h1>
</body>
</html>
•
<head> = Metadata عن الصفحة (مش مرئية)•
<body> = كل اللي بيظهر للمستخدم•
<title> = اسم الصفحة في الـ browser tab•
<meta> = معلومات للـ browser/search engines<head> section.🏷️ HTML Tags & Elements
| Tag | Effect | Example |
|---|---|---|
<b> | Bold text | Bold |
<strong> | Important text (bold) | Important |
<i> | Italic text | Italic |
<em> | Emphasized (italic) | Emphasized |
<mark> | Highlighted text | Marked |
<del> | ||
<ins> | Underlined | Inserted |
<sub> | Subscript (H2O) | H2O |
<sup> | Superscript (x2) | x2 |
<br> | Line break (empty tag) | — |
<hr> | Horizontal rule | — |
NO2 (subscript 2):
<p>NO<sub>2</sub></p>
H2O (subscript 2):
<p>H<sub>2</sub>O</p>
x² (superscript 2):
<p>x<sup>2</sup></p>
Strike+Underline:
<p><del>Hello</del>
<ins>Hi</ins></p>
Highlighted:
<p><mark>Important</mark></p>
<br>, <hr>, <img>, <meta>, <link>دي مش محتاجة closing tag!
<h1>Biggest Heading</h1>
<h2>Heading 2</h2>
<h6>Smallest Heading</h6>
Background color:
<body style="background-color:yellow;">
Text color (both are correct!):
<p style="color:red;">Red text</p>
<p style="color:#ff0000;">Also red!</p>
Font:
<h1 style="font-family:verdana;">
color:red = color:#ff0000 — كلاهما صح!🔗 Links · Images · Lists · Tables
Absolute link:
<a href="http://www.google.com">
Google
</a>
Relative link:
<a href="page2.html">
Page 2
</a>
a = anchor, href = hypertext reference
<a href="..."><img src="..."></a><img
src="photo.png"
alt="My Photo"
style="width:200px"
/>
src = path to image (مش href ومش link!)
alt = نص بديل لو الصورة ما اتحملتش
Unordered (bullets) → <ul>:
<ul>
<li>Item 1</li>
<li>Item 2</li>
</ul>
Ordered (numbers) → <ol>:
<ol>
<li>First</li>
<li>Second</li>
</ol>
<table>
<tr> <!-- table row -->
<th>Make</th> <!-- header cell -->
<th>Model</th>
</tr>
<tr>
<td>Ford</td> <!-- data cell -->
<td>Edge</td>
</tr>
</table>
🚀 HTML5 New Features
HTML5 introduced new <input> types: email, date, time, color, range...
If browser doesn't support → treats as normal text input.
localStorage: permanent (cross-sessions), up to 5MB
sessionStorage: temp, cleared when tab closes
Better than cookies! Data NOT sent to server with each request.
Lets browser save HTML + resources locally for offline use.
Reduces HTTP requests + server load. Faster loading!
| Feature | Cookies | Web Storage |
|---|---|---|
| Max Size | 4KB | 5MB |
| Sent to server? | Yes, every request | No, stays local |
| Expiry | Can be set | Local = forever / Session = tab close |
HTML Quiz — أسئلة حقيقية من الامتحانات
كل الأسئلة من امتحانات Cairo University
HTML DOM — Document Object Model
Tree · Nodes · Finding · Modifying · Events
الـ DOM بيحوّل الـ HTML document لـ tree of objects. كل element وكل text وكل attribute = node.
JavaScript ممكن يوصل لأي node، يعدّله، يضيف جديد، أو يمسح.
nodeType = 1 → Element node (<h1>, <p>...)nodeType = 3 → Text node ("Hello World")nodeType = 2 → Attribute nodenodeName of element = tag name ("H1", "P")nodeName of text node = "#text"nodeValue of element = null!nodeValue of text = actual textparent, child, siblings
parentNode · firstChild · lastChild
previousSibling · nextSibling · childNodes
دي الـ HTML اللي بتيجي في الامتحانات — فهمها كويس!
<h2 id="id1">Hello World</h2> ← NOT a <p>
<p>Welcome</p> ← p #1
<div>
<p>Paragraph 1.</p> ← p #2
<p>Paragraph 2.</p> ← p #3
<section><p>Paragraph 3.</p></section> ← p #4
</div>
<p>Paragraph 4.</p> ← p #5
<p>Paragraph 5.</p> ← p #6
<script>
const my = document.getElementsByTagName("p");
document.getElementById("id1").innerHTML = my.length;
</script>
• عدد <p> elements = 6 → my.length = 6
• h2 innerHTML سيتغير من "Hello World" لـ 6
• إجابة "None of the previous" = الصح (مش 5!) — الجواب الصح 6
🔍 Finding HTML Elements
// 1. By ID — fastest, returns ONE element
document.getElementById('title');
// 2. By class name — returns live HTMLCollection
document.getElementsByClassName('note');
// 3. By tag name — returns HTMLCollection
document.getElementsByTagName('p');
// 4. querySelector — CSS selector, FIRST match only
document.querySelector('#fruits > li');
// 5. querySelectorAll — CSS selector, NodeList (all matches)
document.querySelectorAll('.note');
const h2 = document.getElementById("id1");
// h2 = <h2 id="id1">Hello World</h2>
h2.nodeType; // → 1 (element node)
h2.nodeName; // → "H2" (tag name, READ-ONLY)
h2.nodeValue; // → null (elements have null!)
h2.innerHTML; // → "Hello World"
h2.firstChild; // → text node "Hello World"
h2.firstChild.nodeType; // → 3 (text node)
h2.firstChild.nodeName; // → "#text"
h2.firstChild.nodeValue; // → "Hello World" ← EQUIVALENT to innerHTML!
// So: h2.innerHTML === h2.firstChild.nodeValue
✏️ Modifying HTML Elements
const h1 = document.getElementById('title');
// Change TEXT content (safe, no XSS risk)
h1.textContent = 'New Title';
// Change with HTML (renders tags)
h1.innerHTML = 'Hello <em>World</em>';
// Change style
h1.style.color = 'tomato';
h1.style.fontSize = '3rem';
// Change attribute
const link = document.querySelector('a');
link.setAttribute('href', 'https://example.com');
innerHTML = renders HTML tags (can execute scripts → XSS attack!)innerText = plain text only (SAFE)Always use innerText when dealing with user input!
➕ Add/Delete Elements & Events
// Create new element
const li = document.createElement('li');
li.textContent = 'Buy groceries';
// appendChild → adds at END (last child)
const ul = document.getElementById('list');
ul.appendChild(li);
// insertBefore(new, reference)
ul.insertBefore(newEl, ul.firstElementChild);
// Remove element
ul.removeChild(li); // old way
li.remove(); // modern
// Replace element
ul.replaceChild(newEl, oldEl);
// Modern way (preferred):
btn.addEventListener('click', handler);
// Old way (not recommended):
btn.onclick = function() { alert('hello'); };
// Common events:
'click' // mouse click
'dblclick' // double click
'mouseenter' // hover in
'keydown' // key press
'DOMContentLoaded' // page ready
// Event object:
btn.addEventListener('click', (e) => {
e.target; // element clicked
e.preventDefault(); // stop default
e.stopPropagation(); // stop bubbling
});
// classList API (better than className):
box.classList.add('active');
box.classList.remove('active');
box.classList.toggle('active'); // add if missing, remove if present
box.classList.contains('active'); // true/false
// DocumentFragment (batch insertion, ONE reflow):
const frag = document.createDocumentFragment();
items.forEach(item => frag.appendChild(createRow(item)));
table.appendChild(frag);
// dataset API:
// <button data-user-id="42" data-role="admin">
btn.dataset.userId; // "42"
btn.dataset.role; // "admin"
DOM Quiz — أسئلة حقيقية من الامتحانات
DOM, Node Types, Finding & Modifying
CSS — Cascading Style Sheets
Syntax · Selectors · Properties · Specificity
h1 { /* ← Selector */
color: red; /* ← Declaration */
font-size: 24px; /* ← Declaration */
} /* property: value */
Declaration = color: red (الخاصية والقيمة)
Rule = كل الـ block
1. Inline (highest priority):
<p style="color:red;">
2. Internal (in <head>):
<style>
p { color: red; }
</style>
3. External (separate file):
<link rel="stylesheet"
type="text/css"
href="style.css">
1. Inline (style attribute) — highest!
2. Internal (<style> in head)
3. External (separate .css file)
4. Browser default — lowest!
🎯 CSS Selectors — الأصعب في الامتحانات!
| Selector | المعنى | مثال |
|---|---|---|
E | كل elements من نوع E | p { } |
.class | elements بـ class معين | .note { } |
#id | element بـ id معين | #title { } |
E.class | elements E بـ specific class | p.center { } |
E > F | F اللي هو direct child لـ E فقط | div > p { } |
E ~ F | كل F اللي هم siblings بعد E | div ~ p { } |
E + F | الـ F الأولانية immediately بعد E | div + p { } |
E[attr=val] | E عنده attribute بقيمة محددة | a[target=_blank] |
E[attr^=val] | attr يبدأ بـ val | a[href^="https"] |
E[attr$=val] | attr ينتهي بـ val | a[href$=".pdf"] |
E:first-child | E لو كان أول child لـ parent بتاعه | p:first-child { } |
E:hover | E لما يكون hovered | a:hover { } |
E:enabled | E لما يكون enabled | input:enabled |
E:empty | E اللي مفيش ليه children | p:empty { } |
دي الـ HTML اللي بيجي في أسئلة الـ CSS selectors:
<h2>CSS Selector</h2> ← first child of body
<p>Hello I am Here:</p> ← p#1, 2nd child
<p>Hello I am Here: Paragraph 2</p> ← p#2
<p> Hello I am Here: P3</p> ← p#3
<a href="https://www.w3schools.com">w3schools</a>
<a href="http://www.disney.com" target="_blank">disney</a>
<a href="http://www.wikipedia.org" target="_top">wiki</a>
"p اللي هو أول child لـ parent بتاعه"
في الـ body، أول child هو <h2> مش <p>
∴ مفيش p هو first-child → 0 elements
بس disney.com عنده target="_blank"
wikipedia عنده target="_top" مش _blank
<p>Welcome</p> ← p before div
<div>
<p>Paragraph 1.</p> ← direct child of div ✓
<p>Paragraph 2.</p> ← direct child of div ✓
<section><p>Paragraph 3.</p></section> ← NOT direct child ✗
</div>
<p>Paragraph 4.</p> ← sibling after div ✓
<p>Paragraph 5.</p> ← sibling after div ✓
Only P1, P2 are direct children. P3 is inside <section>.
P4, P5 are siblings after the div. P before div doesn't count.
Only P4 (immediately next sibling after div).
📦 Box Model & CSS Properties
Margin = مسافة خارج الـ element (بين العنصر وجيرانه)
Padding = مسافة داخل الـ element (بين الـ content والـ border)
Border = الـ border بتاع الـ element
السؤال "space INSIDE the element" → Padding
السؤال "space between elements" → Margin
background-color: yellow;
background-image: url('img.png');
background-position: center top;
background-attachment: fixed;
font-size: 16px;
font-family: Arial, sans-serif;
color: #ff0000; /* = red */
CSS Quiz — أسئلة حقيقية من الامتحانات
Selectors · Priority · Properties
Quick Reference Cheat Sheet
ملخص سريع لكل المنهج — حفظه قبل الامتحان!