why they call ASGI a server while they say it is not in django?

137 views Asked by At

i am studying Channels in Django Frameworke.

after that i went to study ASGI specification , but i got confused of :

First

they say that the ASGI is a server in here.

after that they say that the ASGI uses the Daphne as the main server to work in here.

now is the ASGI middle ware uses server in it or it is server or what does daphne do in ASGI.

second

what do they mean by application in ASGI

is the application above the consumer that will work after the connection is came into it through a WebSocket Protocol ?

i have read a lot and read the whole document but in technology every time there is something missing.

thanks

1

There are 1 answers

0
CodeMaven42 On BEST ANSWER
  1. Understanding ASGI (Asynchronous Server Gateway Interface):
  • ASGI acts as a specification that allows Django and other frameworks to support asynchronous, real-time operations such as WebSockets.
  • ASGI itself isn’t a server; rather, it’s a protocol that enables communication between servers, applications, and middleware in an asynchronous manner.
  • Daphne is indeed a server, specifically designed to handle ASGI applications. It’s commonly used with Django for handling WebSocket connections and other asynchronous operations.
  1. ASGI Middleware and Daphne:
  • ASGI middleware sits between the server (like Daphne) and your application. It intercepts incoming requests, allowing you to perform operations like authentication, logging, or modifying the request/response.
  • Daphne, as the ASGI server, manages the communication between the client and the ASGI application. It accepts incoming connections and routes them to the respective ASGI application.
  1. Understanding the ASGI Application:
  • In ASGI, an application refers to the core logic that handles incoming connections and performs specific actions.
  • This application is a layer above the consumer. Once a connection is established (like a WebSocket connection), the application defines how to handle incoming messages, manage state, and execute logic based on those messages.
  • Consumers are essentially instances of your application that manage individual connections. They define how your application handles WebSocket events (like receiving a message or closing a connection).

In summary, ASGI isn’t a server itself but a protocol that enables asynchronous communication. Daphne serves as the ASGI server, while the ASGI application represents your core logic that handles incoming connections and defines how to handle WebSocket events through consumers. ASGI middleware sits between the server and your application, allowing for custom processing of incoming requests.