So what I wanted to do now is I want to give you an example of a communication proxy and we're going
to see how we can relocate a sudden piece of functionality from the local process into some web server
somewhere.
So let's imagine that we have a very simple interface I'm going to make an interface gulping pinball
ping.
So the idea behind this interface is it's got a single function called ping
which takes a message of some kind and it appends the word pong into this message and returns the overall
string.
So if you feed it a message containing x it will give you X pong.
If you give it the message ping it will give you the message ping pong.
So when making a ping pong service effectively now what I can do first of all is I can make such a process
which is local so I'm going to have a structure called Pong which is singable.
And here I will implement the missing member.
Hopefully there is a generator here for that.
And what we're going to do is we're just going to return the original message plus the string palm with
a space in between so we can have some sort of functionality for actually using pinging objects.
So for example I can make a function called Try it which takes a ping and just does it three times for
example.
So here is a function call a try it.
It takes a ping a ball and it just outputs the result of calling ping three times.
Well let's let's just do it once.
Let's do it three times from the main.
So here I'm just going to say ping ping with the message ping and then let's put a line break at the
end of it.
So what I'm going to do is I'm going to call it three times and I'm expecting to get ping pong three
times.
So I make an instance of Pong which is once again a local local construct something which is in process
and then I'll make a for loop going three times.
And here I will call it try it's passing in this pong object that I have constructed.
So this is our demo.
It's not a particularly sophisticated demo.
I can actually execute this and you can see ping pong being printed three times.
Now here is the idea behind the communication proxy.
Let's suppose that one to keep the interface I want to keep the interface Pingo but whenever somebody
actually calls ping this functionality the functionality of adding the word porn onto the end of the
message actually happens on some remote server somewhere and I can actually do this.
So here is a second project that I have in the solution and I'm using visuals here instead of Sea-Lion
because this is the Windows world.
So here is a second project where I have an ISP that core restful application which just has a single
get processor which gets some message and returns that message with the word polling data.
So what can I do with this.
Well on the side of the AP though what I can do is I can actually run this service so I can just control
it 5.
And this this executes the whole thing.
And then what I can do coming back to the communication proxies I can actually build the communication
proxy and the way this is done is by once again adhering to the same interface that we had previously.
So we're going to make something that's possible.
But whenever you call ping on it.
Well completely different things happen.
Now in order to make this possible what I've done if we look at the New get packages that I'm actually
using here you're going to see that I've actually referenced a package called CPV rest as the case so
this is the C++ rest as the k.
It's very useful for working with restful Web services.
It's cross-platform open source.
It's all the goodness and yes it does comes from Microsoft of all companies.
OK so here's the idea.
So we want to build the communication proxy which means that we want yet another type that's called
Remote pong which actually does all the communication with that web service.
So what I'm going to do is I'm going to just pace the implementation in here and then we can look at
it.
So as you can see I'm using a couple of headers from the rest SDK.
I'm also having a couple of using namespace directives and here is remote pongs So as you can see it's
also being MBO.
So it has the same interface as an ordinary pong but the difference is that when you call the function
which has the same signature it doesn't actually execute locally what happens instead is you connect
to a service and by the way here I need to actually make sure that the port number is correct because
I have it on then I use Express where the port changes so that's based the correct port in here.
So I'm building the query I'm sending the data and then I'm getting the response and I am returning
that response here.
So this is how you make a communication proxy which looks as though it's in process but in actual fact
it's going off to some remote server somewhere and doing its thing.
So all we can do now in terms of switching from one to another is instead of bhang all we can do a remote.
And that would be the only change that you would actually have to make in order for the communication
proxy to kick in and start working instead of the in process variety.
So what's going to happen now as we execute this is going to take a bit of time to actually compile.
But essentially get the same result as before but we are getting this result not through local in process
execution but actually invoking something which is being run on a web server somewhere.
So this is how you make a communication proxy it's a very simple idea and one which would allow you
to substitute local objects for example with objects somewhere in the cloud.