0Pricing
WebSockets & Realtime Systems Programming · درس

إقرار استلام الرسائل وضمانات التسليم

اضمن عدم فقدان الرسائل بصمت عبر إضافة إقرارات الاستلام وإعادة المحاولات وقابلية التكرار لتحقيق ضمانات تسليم موثوقة.

إقرار استلام الرسائل وضمانات التسليم درس مجاني في WebSockets & Realtime Systems Programming على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في WebSockets & Realtime Systems Programming، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة WebSockets & Realtime Systems Programming 4 دروس في المجموع.

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

Messages Can Vanish

A message can be lost if the socket drops mid-send, the server crashes, or the client reloads before processing. Without acknowledgements, neither side knows it happened.

Delivery Guarantee Levels

Three common guarantees:

  • At-most-once: may lose, never duplicate
  • At-least-once: never lose, may duplicate
  • Exactly-once: never lose, never duplicate (hardest)

Application-Level Acks

WebSockets only confirm transport delivery, not processing. To know a message was handled, the receiver must send an explicit ack back.

Adding a Message Id

Tag each message with a unique id so acks can reference it.

const msg = { id: crypto.randomUUID(), type: 'order', data };
ws.send(JSON.stringify(msg));

Sending the Ack

The receiver replies with an ack carrying the original id once it has safely processed the message.

ws.send(JSON.stringify({ type: 'ack', id: msg.id }));

Tracking Unacked Messages

The sender keeps a map of in-flight messages until their ack arrives.

const pending = new Map();
pending.set(msg.id, msg);

Retrying on Timeout

If no ack arrives within a timeout, resend the message. This is how at-least-once delivery is achieved.

setTimeout(() => {
  if (pending.has(msg.id)) ws.send(JSON.stringify(msg));
}, 3000);

The Duplicate Problem

Retries can deliver the same message twice (e.g. the ack was lost, not the message). At-least-once therefore implies the receiver may see duplicates.

Idempotency to the Rescue

Make processing idempotent: handling the same id twice has the same effect as once. Track seen ids and ignore repeats.

const seen = new Set();
if (seen.has(msg.id)) return;
seen.add(msg.id);
process(msg);

Approaching Exactly-Once

True exactly-once is impossible to guarantee end-to-end, but at-least-once delivery plus idempotent handling gives the same practical result, which is what most systems use.

Best Practices

Build reliable delivery:

  • Tag messages with unique ids
  • Require application-level acks
  • Retry unacked messages with a timeout
  • Make processing idempotent to absorb duplicates

Quick Check

Test your delivery knowledge.

Recap

You added delivery guarantees to realtime messaging:

  • Understand at-most/at-least/exactly-once
  • Use message ids and application-level acks
  • Retry unacked messages
  • Combine at-least-once with idempotency

Your system no longer silently loses messages.

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

هل درس «إقرار استلام الرسائل وضمانات التسليم» مجاني؟

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

ماذا ستتعلم في «إقرار استلام الرسائل وضمانات التسليم»؟

اضمن عدم فقدان الرسائل بصمت عبر إضافة إقرارات الاستلام وإعادة المحاولات وقابلية التكرار لتحقيق ضمانات تسليم موثوقة. تتمرن على WebSockets & Realtime Systems Programming مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ WebSockets & Realtime Systems Programming؟

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

كم من الوقت يستغرق درس «إقرار استلام الرسائل وضمانات التسليم»؟

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

هل يمكنني كتابة وتشغيل أكواد في درس WebSockets & Realtime Systems Programming هذا؟

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

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

  1. التعامل مع انقطاع الاتصال وإعادة الاتصال
  2. نشر الأخطاء والتعافي منها بموثوقية
  3. نبضات الاتصال والحفاظ عليه
  4. إقرار استلام الرسائل وضمانات التسليم
← العودة إلى WebSockets & Realtime Systems Programming