You are on page 1of 7

REAL-TIME WEB

Il futuro a portata di
mano

What is real-time?

Real-time Web identifies the execution of an operation of any nature, in an extremely


short time.
Applied to the context of the Web, Real-time Web identifies the kind of communication
operations that take place over the Internet and that are not affected by delays or
latencies, and thus are performed very quickly.
But we must be realistic, our country hasnt got the fastest networks, and this is a strong
limit on the development of real-time web. But apparently, even in this bad context,
there is a light of hope, but Ill talk about that later.
Meanwhile, to better understand the concept of Real-time web, I would like to give you
some examples
Who uses the real-time web?
The clearest example of the use of real-time web is a common chat line. But if we pause
to think more carefully about the subject, Real-time technology is used more frequently
than we expect.
In fact, in addition to the common chat lines, we can find this type of technology in some
of the functionality of the most famous websites. Just think about the notifications of
Facebook or Twitter, that come to us in real time, or the speed of Google searches. Then
there are also some video games that use the network to interface with other users in
real-time.
But does the usefulness of real-time end here?
If you have the necessary tools, the use of real-time technology can expand to additional
fields (think for example about mobile calls, or infrared communication).
These devices do not use the Internet, and this can be both their advantage and their
disadvantage: in fact the infrared communications (or even Bluetooth), after a few
meters of distance from the receiver, stop working. Then mobile-line calls are limited and
expensive.
The cloud
A buzzword born in recent years is cloud computing. What is cloud computing? It is a
new way for approaching to the world of the Internet. Cloud computing is essentially the
set of the functions provided for storing, processing or transmitting the information using
the Internet. Cloud is the foundation of the most popular web services (Facebook, Google
and Flickr). To be honest, every web application which stores or processes data is
theoretically based on the cloud computing.
It is an extremely new way to use the internet, because, instead of using large and
expensive local servers for storing or processing data, everyone can use the cheaper,
faster and simpler clouds. Then, the cloud can also be reached from anywhere in the
world, and its performances will never decrease.

A cloud server is very scalable then. In fact, if you need to increase the workload that the
cloud has to do, you only have to increase the power of your cloud, and it can be done
very easily.
What if we can mix cloud computing and real-time?
Using Real-time technology together with the cloud, means aligning the power of a realtime communication with the flexibility and accessibility of the cloud.
It would mean to leave the common vision of the cloud, which is seen as nothing more
than an online hard-disk for storing information. It would mean starting to use this
powerful tool in a more completely way.
And with this line of thought, I want to show you my project: Remote Mobile Manager.

Remote Mobile Manager


What is Remote Mobile Manager?
Remote Mobile Manager is a small project, composed (for now) of three applications:
-

RMM Controller (for Windows Mobile, Android and iOS)


RMM PC Side (for Windows PCs)
RMM Web Server (hosted online)

The target of this project is to make it possible for every person to manage an electronic
device from every place in the world, using the Real-time web. Only Windows PCs have
been used.
The features of this application are still many: you can administrate your PC from
everywhere you are, using a very small amount of Internet traffic. It can be used as a
remote controller in the same way as it can be used to check what the PC is doing.
The mobile application is divided into seven pages.
The first one is used to select the PC (or the device) you want to connect to, and then to
establish the connection with it.
Then there is a page that allows you to manage the files and the directories in your PC.
You can copy and move every element from anywhere to anywhere. You can even
rename o delete every file or directory in your PC.
The third page administrates the boot operations of the PC, so from this page you can
shutdown, reboot, suspend or block your device. You can even set a timer or a date in
which the PC will shutdown.
Then there is the screenshot page. From here you can have a screenshot of your PC
desktop on your phone, just for checking what it is doing.

The other two pages allows you to start MP3s or videos remotely, by selecting them from
the menus in the app. After starting a song (or a video), you can pause it, skip to the
next one, and so on.
At the end there is the last page, whose target is to control the slideshow in Power Point
(just moving to the next or the previous slide).
The RMM Web Server works with a cloud hosting, and it has the task to handle every
request that comes from the client devices (both the Smartphone and the Windows PC
are clients).
The RMM PC Side is a tray application installed in the desktop PC, and it has the job to
execute every request coming from the Web Server (only in the case of the screenshot,
the application answers the server with the image to upload).
At the base of this application there are the WebSockets, and now its time to start
talking about this powerful technology.

Web Sockets
Per sfruttare al meglio le capacit dellinnovativo linguaggio di programmazione web
HTML5 il World wide web Consortium (W3C) ha standardizzato di recente una nuova e
potente tecnologia, chiamata WebSocket.
Cos il WebSocket?
Da definizione, il WebSocket la tecnologia che permette di instaurare un canale di
comunicazione full-duplex con ununica connessione TCP.
Detto in parole semplici la tecnologia che permette di comunicare con una risorsa web
alleggerendo pi possibile il carico di traffico inviato o ricevuto e massimizzandone le
prestazioni.
Il WebSocket, nella sua standardizzazione, stato definito come una tecnologia realtime, che differisce in maniera sostanziale da tecnologie come il long-time polling (che
vengono definite near real-time), utilizzate per le attuali applicazioni Web (Web API).
Ci significa che la trasmissione dei dati tramite WebSocket avviene con una velocit
elevatissima, in tempo reale praticamente.
Utilizzare questo tipo di tecnologia, per, complesso, e prevede la conoscenza di
linguaggi informatici non sempre rapidi da apprendere.
Microsoft prende la palla al balzo
Microsoft, nel suo continuo essere in ritardo, si comunque chiesta: Bene, ora
sappiamo che esiste questa tecnologia. La possiamo offrire ai nostri programmatori in
maniera uniforme e semplificata?
La risposta non tarda a farsi sentire:

SignalR.
Che cos SignalR?
SignalR una libreria ideata in principio per i programmatori di web server che utilizzano
ASP.NET MVC (modello di sviluppo di web server basato su Visual Basic e C#, linguaggi di
programmazione proprietari di Microsoft).
La libreria, per quanto proprietaria di Microsoft, per progettata in jQuery, una
estensione del JavaScript (anche questo linguaggio usato per lo sviluppo di applicazioni
web).
Originariamente concepito per essere utilizzato in un gioco online di nome ShootR,
SignalR stato rilasciato come libreria ufficiale di ASP.NET, e ad oggi, probabilmente
lunico mezzo che permette di interfacciarsi al mondo dei WebSocket in maniera
semplice e intuitiva.
La libreria esiste da poco, ma in questo poco tempo stata estesa per funzionare non
pi unicamente sul framework .NET (Microsoft) ma anche sul framework Mono, sul quale
si basano le applicazioni iOS e Android. Dunque la flessibilit di questa libreria ha
raggiunto anche il mondo del mobile.
Possiamo quindi annoverare SignalR tra le pi semplici e potenti tecnologie che il mondo
informatico possa offrire.
Come funziona SignalR?
SignalR sfrutta HTTP attraverso i WebSockets. Chiaramente, per, questo tipo di
comunicazione non supportata da tutti i dispositivi, e quindi Microsoft ha implementato
in esso anche metodi di scambio di informazione pi lenti, ma pi retrocompatibili (come
ad esempio il long polling, per riprenderne uno sopracitato).
SignalR pone alla base di queste tecnologie real-time (o near real-time) due tipi di
connessione:
-

Connessione Persistente
Connessione Hub

La connessione Persistente sarebbe quella pi completa, ma anche la pi complessa.


Essa infatti prevede lo stabilimento di un canale di connessione logico allinizio della
sessione di comunicazione, e labbattimento dello stesso alla fine della comunicazione.
Gran parte delle esigenze possono, per, essere sopperite dai pi semplici Hub SignalR,
che son quelli che andr a spiegare pi dettagliatamente (e quelli che ho utilizzato nel
progetto).
Questo tipo di connessione si basa su modello Client Server.
Vi sono infatti dei dispositivi, su cui gira lapplicativo SignalR, che rivestono il ruolo di
client (sviluppati su .NET Framework o Mono Framework).

E quindi c un server online (costruito opportunamente in ASP.NET MVC) che ospita un


hub.
Questo hub ha il compito gestire tutte le richieste in arrivo dai client.
Detto in termini pratici un dispositivo client invoca una procedura scritta dal
programmatore nellhub, e fornisce a questa procedura anche i dati di cui ha bisogno per
operare.
La procedura opera quindi sui dati arrivati
In seguito la stessa procedura potrebbe decidere di operare sul server stesso (ad
esempio memorizzare un valore in arrivo), inoltrare dati processati al dispositivo che ha
invocato la procedura o inoltrarli verso altri dispositivi.
Lhub quindi conserva la stessa metodologia di comunicazione del client, in quanto
anche lui effettua una invocazione ad una procedura descritta nel codice sorgente
dellapplicazione client.
Ci che rende per questa tecnologia spaventosa la sua velocit. Generalmente queste
operazioni nelle classiche Web API impiegano un tempo dieci volte maggiore per essere
portate a compimento rispetto a SignalR.
Perch utilizzare SignalR?
Oltre alla velocit di trasmissione, che comunque abbatte (almeno in parte) i limiti
imposti dalle reti lente, SignalR permette di inviare input ad un dispositivo senza che
lutente debba interfacciarsi ad esso. Questo input pu essere inviato a qualsiasi
dispositivo che permette il funzionamento di una applicazione sviluppata in C# (o in
Visual Basic) e che sia connesso alla rete. Il mio progetto, lintera applicazione
sviluppata attraverso SignalR.
Conclusioni
Windows 10, con il suo IDE Visual Studio 2015, ha implementato uno strumento di
sviluppo per lInternet of Things che permette di eseguire il deploy di una applicazione
sviluppata in C# su piattaforme quali Raspberry e Arduino
Ci significa che in un futuro molto vicino, si potr utilizzare la tecnologia real-time web
di SignalR per fare in modo che un dispositivo elettronico possa accendere o spegnere un
elettrodomestico. O ancora poter comandare droni unicamente utilizzando la rete
internet. E perch no, comandare a distanza di migliaia di chilometri macchinari
industriali.
Le possibilit sono veramente infinite, e i mezzi ci sono. Basta un pizzico di buona
volont per rendere una computer, una casa, un paese o lintero mondo pi smart.

Gian Marco Barbato


Bibliografia

English for new technology Kiaran OMalley Pearson 2012 Milano, Italia
Pro ASP.NET SignalR, Real-Time communications in .NET with SignalR 2.0 Keyvan
Nayyeri, Darren White Apress 2014

You might also like