0Pricing
WebSockets & Real-Time Systems with Spring · درس

أساسيات بروتوكول WebSocket

تعمّقوا في بروتوكول WebSocket الأساسي، بما في ذلك المصافحة والإطارات ودورة حياة الاتصال.

أساسيات بروتوكول WebSocket درس مجاني في WebSockets & Real-Time Systems with Spring على CoddyKit. هذا هو الدرس 3 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في WebSockets & Real-Time Systems with Spring، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة WebSockets & Real-Time Systems with Spring 4 دروس في المجموع.

بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.

Beyond HTTP: The WebSocket Protocol

WebSockets feel like HTTP but are a distinct protocol. They open a persistent, full-duplex link so data flows both ways at once after setup.

Starting with a Handshake

Every WebSocket starts with a handshake: the client sends a normal HTTP request asking the server to upgrade the connection to WebSocket.

Client's Upgrade Request

The client's upgrade request is an HTTP GET with key headers: Upgrade: websocket, Connection: Upgrade, plus Sec-WebSocket-Key and Version.

Server's Acknowledgment

If the server accepts, it replies with 101 Switching Protocols and a Sec-WebSocket-Accept header derived from the client's key, confirming the upgrade.

Witnessing the Handshake

Watch the handshake yourself: run this in your console, open the Network tab, and look for the 101 Switching Protocols response.

/*
  Open your browser's developer console (F12),
  go to the 'Network' tab, then paste and run this code.
  Look for a '101 Switching Protocols' response!
*/
let ws = new WebSocket("wss://echo.websocket.org");

ws.onopen = (event) => {
  console.log("WebSocket connection opened!");
};

ws.onclose = (event) => {
  console.log("WebSocket connection closed!");
};

ws.onerror = (error) => {
  console.error("WebSocket error:", error);
};

// We'll send messages in later lessons!

Connection Established: Full-Duplex

After the handshake, the connection upgrades to a raw TCP link that is full-duplex: client and server send and receive independently, anytime.

How Messages are Sent: Frames

WebSocket data travels in small units called frames. Framing lets large messages fragment efficiently and supports different control message types.

Different Types of Frames

WebSocket frame types each have a job: text for strings like JSON, binary for raw data, ping/pong for heartbeats, and close to end the connection.

The Connection Journey: Lifecycle

A WebSocket follows a clear lifecycle: opening (handshake), open (exchanging frames), closing (graceful shutdown), and closed.

Quick Check: WebSocket Fundamentals

Which of the following are true about a WebSocket connection after a successful handshake?

Recap: WebSocket Protocol Essentials

You demystified the WebSocket protocol: an HTTP handshake upgrades to a persistent full-duplex channel, data moves in frames, and connections follow a lifecycle. Next: comparisons.

الأسئلة الشائعة

هل درس «أساسيات بروتوكول WebSocket» مجاني؟

نعم — نص درس «أساسيات بروتوكول WebSocket» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة WebSockets & Real-Time Systems with Spring، انتقل إلى CoddyKit PRO. تتضمن دورة WebSockets & Real-Time Systems with Spring 4 دروس في المجموع.

ماذا ستتعلم في «أساسيات بروتوكول WebSocket»؟

تعمّقوا في بروتوكول WebSocket الأساسي، بما في ذلك المصافحة والإطارات ودورة حياة الاتصال. تتمرن على WebSockets & Real-Time Systems with Spring مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ WebSockets & Real-Time Systems with Spring؟

لا تُشترط خبرة سابقة. WebSockets & Real-Time Systems with Spring على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 3 من أصل 4.

كم من الوقت يستغرق درس «أساسيات بروتوكول WebSocket»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس WebSockets & Real-Time Systems with Spring هذا؟

نعم. كل درس في WebSockets & Real-Time Systems with Spring يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. فهم الاتصال الفوري
  2. WebSockets مقابل HTTP Polling
  3. أساسيات بروتوكول WebSocket
  4. Server-Sent Events مقابل WebSockets
← العودة إلى WebSockets & Real-Time Systems with Spring