• We've already learned about the Socket Library, a Socket Library is a very low-level library.


  • It's very useful, but there's more work for the programmer to do, meaning the programmer is left to handle a lot, a relatively large amount of details when it comes to this, using the Socket Library to send a message.


  • So specifically, the programmer has to compose the message content, so that means that the programmer has to be aware of what the network protocol defines as the message to look like.


  •  
        mysock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        host = socket.getHostByName("www.google.com")
        mysock.connect(host,80)
        message = "GET / HTTP/1.1\r\n\r\n"
        mysock.sendall(message)
        
    
    
  • For instance, the first three lines you see above, all this is doing is connecting to Google.com and sending it a http get message.


  • Now, this is a very simple message, but you had to know protocol specific details to know what that message should look like. The fact that the word get has to be the first thing you see, get or put or something like that.


  • There are several headers that have to be first, and you have to know that about HTTP rather, in order to make that message.


  • So using the bare Socket Library can be tedious for a programmer because they have to worry about all those details.


  • It is nice sometimes to use protocol-specific libraries and there are several of these available in Python and for the Raspberry PI and so forth.


  • And so these libraries, they are, you have several, a lot of these just for one protocol. 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.


  • 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.


  • These type of web based library functions are called APIs.


  • Web-based services mean services in the cloud as some service that is run on remote servers that are accessible through the network.


  • These are services that typically Raspberry Pi can't, doesn't have the ability to do maybe it's too computationally intensive, the task that it performs, or maybe it just doesn't have the data that it needs.


  • The web service runs on a remote server except like Facebook and they accept requests from clients like your Raspberry Pi


  • And they interact typically using HTTP messages.


  • And it adds a lot of power to your system, right, because a Raspberry PI alone can only do so much. But if you want to be Internet of Things, and this thing needs to communicate with the internet and access these remote services.


  • So this is a very common thing that IoT devices can do is sort of access bigger services provided by servers somewhere out there on the network.


  • A lot of these protocols are stateless, that is, you send one message, you get one response, and there's no memory of a previous sequence of things that happened before


  • SDK is another term that is related in this context - Software Development Kit. It's a set of tools to support the use of an API. Now, that can mean different things, typically what it means is it's a bunch of library functions that support the use of the API.


  • So, an API just tells you the format, what the messages should look like and how they should be formatted. The SDK is supposed to be, it's typically a bunch of library functions that adhere to that API.


  • What that means is that the programmer doesn't need to know the details of the API because the SDK acts as an interface for him or her. So for instance, if you want to send a message to get a map from Google Maps


  • One way would be to just know the API and then, you create a string request and then you send that. Or if you have an SDK, the SDK might have a library function in there and then it's the job of that function to actually create the proper request message and send it out. So it makes it easier.


  • If you have an SDK, you have these library functions where you don't even have to know the details of the API.


  • You just call the library functions and they handle all the details. So SDKs are good.