Bird
0
0

What happens if you forget to call await self.accept() inside the connect method of a WebSocket consumer?

medium📝 component behavior Q5 of 15
Django - Async Django
What happens if you forget to call await self.accept() inside the connect method of a WebSocket consumer?
AThe server will send a default acceptance message
BThe WebSocket connection will be rejected and closed
CThe connection will stay open but no messages can be sent
DThe client will automatically reconnect
Step-by-Step Solution
Solution:
  1. Step 1: Understand accept() role in connect

    Calling accept() confirms the WebSocket connection; without it, connection is rejected.
  2. Step 2: Review consequences of missing accept()

    Without accept(), the server closes the connection immediately.
  3. Final Answer:

    The WebSocket connection will be rejected and closed -> Option B
  4. Quick Check:

    Missing accept() = connection rejected [OK]
Quick Trick: Always call await self.accept() to open WebSocket connections [OK]
Common Mistakes:
MISTAKES
  • Assuming connection stays open without accept()
  • Thinking server sends default acceptance
  • Believing client auto-reconnects on missing accept()

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes