In this video, I'm going to show you around the DDP package. It's the core Meteor package that's responsible for giving us Pub/Sub, and Meteor Methods, and the DDP wire protocol. To start us off, I want to show you what happens when we initially make an HTTP request to a Meteor application. So up top, I've got a simple Meteor app running, and I'm using a special package that will show us the requests that come off the wire.
We'll start off using cURL as the client. And the reason for that is so that you can see the text response that comes back from the server. And in a second we'll go over to the browser. There's a few things to notice here. Up top, there's been one HTTP request made to the Meteor server for the root URL. And that's what's returned this HTML down here. Notice we get it 200 status code back saying that the request was OK, and a bunch of headers.
And then in the HTML body down here, you see a bunch of script tags in the head section, one for each package that we're using. So here's underscore, for example. If I scroll down a little further, you can see the DDP package loaded here. So what's going to happen when we run this in the browser is that for each one of these script tags a new HTTP request will be made to the server for that resource.
So here's a simple diagram of what we just witnessed. We have a client, which was initially cURL, or it could be a browser, and then we have the Meteor server. And we make our initial request to the server using HTTP. We just request the root of the application. And what we get back is some HTML and some script tags. And then, the client can make an additional request for each one of those script tags.
And so finally, when we get to the DDP package, we load that file into the browser and start executing it. And so one of the things that the DDP client does is it opens up a connection with the server. And it's a special kind of connection. It's not like HTTP. It's a DDP connection over Web Sockets. So it's persistent, and it stays open for the entire lifespan of the application.
And the second is we use this wire protocol and the code on the client and the server to get Publish and Subscribe, so Pub/Sub. And the third big thing that we get is Meteor Methods, are Meteor's implementation of remote procedure calls. So let me take you around to the actual package so you can see where these files live in the Meteor core. I've opened up the source code for the DDP package. It's located in the packages directory of the Meteor source.
And you can see it's a pretty big package, because it implements a lot of the functionality that we get in the Meteor framework. The file that I just opened up is Client Convenience, and I wanted to show you the code that's getting executed on the client when this DDP.js file loads up in the browser. So one of the lines in this application, or in this file rather, is meteor.connection equals DDP connect. And so, this is where we're actually connecting to the DDP server, the meteor DDP server, and keeping a connection open with it.
And that's stored in this meteor.connection object. I've opened up the package js file for the DDP package. And you can see there's a bunch of files here that run on the client, on the server, and in both places. And so, this will give you a sense of which code runs in which place.