Now the programmer doesn't have to know the protocol details in this case.
So they can just rely on these library functions that are available that
handle the details.
So it handles, as a for instance, the character turn line keys.
It'll put those in.
And they'll put them in the right place in the message and things like this, right?
So you just call these functions that where the arguments of the functions are,
the key details, the key information that you want to put in this message and
then the library function just composes it into the appropriate type
of string of data, series of data and then sends that for you.
And then on the other end, it receives it.
It does the same thing on receipt.
So they'll be library functions that maybe receive a message of a particular type,
and rather than showing you the whole raw message, they pulled out the important
things, you know, the payload and so forth that you're interested in and
strip away the rest so that you don't have to see that in the program.
So using these application specific or rather protocol specific libraries
can be very helpful sometimes and make it a lot easier.
So one of these libraries called, well there's the http library, right?
So you can import http client,
then if you want to send that same get message, you say con equals,
you call this function, they provide you an http lib called http connection, right?
So you call that function, and
you just give it the name of the domain that you want to go to.
So, this actually does a DNS lookup, but it also establishes a connection.
It rolls it up in to one function, and then conn.request, GET and
then /, that is actually what sends the request message.
So, notice that you're just giving the key details.
You're saying, look, GET, this what I want to do,
this is the type of header I want.
And then /, this is the directory of the file that I want.
You just give those key details and
it composes the bytes that it needs to send in the request.
And this actually sends the request for you, so this makes it easier.
Now this isn't, the difference between this and what we saw in the last slide,
isn't that big because the thing on the last slide was pretty simple as it was.
But this can be very helpful for more complicated types of messages.
So even here, you don't have to worry about exactly how the data is going to be
arranged in the packet, in the message in the headers.
You just give it the key data to get in the slash and it composes the rest.
So protocol specific libraries are very helpful in that way.
And there are a lot of them for a lot of different protocols,
we won't go through all those.
But you should know this for future, like for the capstones say, when you want your
Raspberry Pi to interact with something on the network, you don't necessarily have to
work from scratch with socket library, and learn a whole protocol, right?
Say you know you want your HTTP, you want your,
say you know you want your Raspberry Pi to not HTTP, let's say another protocol.
Let's say you want to talk to a mail server,
you want to send some mail, for instance, okay, send email.
So email the typical protocol is called SMTP, so
if you want to send mail you have to compose that mail and
then make a message in the format of SMTP, defined by that protocol.
Now you don't know that protocol, now you can look up that protocol.
You can Google SMTP and
find an information about what that protocol looks like.
But an easier way is just to import SMTP lib and
I then use the function that are provided in there to send the email.
It makes it much easier, right.
So just remember that for the future.
You don't want to build everything from scratch if you can help it.
If there's any protocol, there's no way we can go through all the different protocols
there are, but the different networking protocols at the application level.
But look for application level protocols specific It libraries for
any particular protocol that you're going to interact with your Raspberry Pi.
Along those lines, let's talk about how you interact with an online service.
So what we mean by this is, say there's Raspberry Pi, it's a nice little machine.
But it's small, relatively small okay.
It only has so much computing power, it only has so much resources, so
much information, right.
So in order to get interesting things going on you're going to need, depending
what you want to do, you might need your Raspberry Pi to connect to the cloud,
the web in general, or the cloud, and
offload some of it's job to the cloud, or get information from the cloud, right?
So what happens is, the way this works is there are these online services.
This service is already out there on the web that do something for you, okay?
That do some tasks for you and maybe it's a computational task that your raspberry
pie can't do fast, or something like that, or
maybe it's accessing data that your raspberry pie doesn't have locally.
So these services, they allow you, your machines to connect to them.
So you can make a request, you send a message from your say,
Raspberry Pi, to their servers with some kind of request in there,
please give me this data, please perform this operation, something like that.
And then the server sends back a message to your device with the results.
So there are a lot of online services like this, a whole lot.
They're pretty interesting to use.
So, for instance, Google Maps, right?
Say you want to make a webpage and you want to have a Google map in there.
Say I want to have a webpage with my office in there,
direct people to my office, something.
And I want to have Google Maps, you know,
a map in there with my address highlighted, my location highlighted and
directions to my house and whatever, my office.
So something like that, I would make a webpage and
I want to have, I might want to have code that interacts with Google Maps,
that allows people to do certain search and basically what you do on Google Maps.
You can do it through my page.
[COUGH] So there's an interface for that, that's an online service.
And you can send it a message, a request message, send Google servers a request
message, please give me this map, and give me these directions, whatever.
It'll send them back, and you can put them on your webpage.