Actividad integradora 6 CREAR UN RECURSO MULTIMEDIA
Aplicaciones Real-Time con SignalR
1.
2. • ¿Por que necesitamos aplicaciones
real-time?
• ¿Que tecnologias tenemos disponibles
para desarrollar aplicaciones real-time?
• SignalR
• Connections y Hubs
• Clients
• Preguntas
3.
4. Twitter – live searches/updates
Stock streamers
Auctions
Live scores
Real-time notifications
Interactive games
Collaborative apps
Live user analytics
…
6
11. Extensión de HTTP
Provee sockets sobre HTTP
Full-duplex
Funciona a través de proxies
No todos los proxy servers lo soportan
No todos los webserver lo soportan
No todos los browsers lo soportan
¡Son sockets!
19. PersistentConnection
Limitado a enviar mensajes
El usuario define el “protocolo”
Hub
Abstracción sobre PersistentConnection
Se pueden enviar mensajes y llamar a
métodos
SignalR define el protocolo
That’s a lot of options, a lot of things to account for and a lot of different programming models. Are you going to do this?
Are you still writing separate getDocumentById and AttachEvent methods to work with the DOM? What about jQuery?
Open the previously created sample
Install-Package jQuery.UI.Combined
Add a class:
[HubName("worker")]
public class WorkerHub
: Hub
{
public void startProcessing(Event e)
{
Caller.notify("We've started processing " + e.EventName);
Clients.setProgress(10);
for (int i = 0; i <= 100; i++)
{
SignalR.Hubs.Hub.GetClients<WorkerHub>().setProgress(i);
Thread.Sleep(100);
}
}
}
Add some HTML:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<link rel="stylesheet" href="Content/themes/base/jquery.ui.all.css" />
<script src="Scripts/jquery-1.6.4.min.js" type="text/javascript"></script>
<script src="Scripts/jquery-ui-1.8.16.min.js" type="text/javascript"></script>
<script src="Scripts/jquery.signalR.js" type="text/javascript"></script>
<script src="signalr/hubs" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
var workerHub = $.connection.worker;
$('#progressbar').progressbar({ value: 0 });
$('#startWorkTrigger').bind('click', function () {
workerHub.startProcessing({ eventName: 'UAN12' })
.fail(function (e) {
alert("An error occured: " + e);
});
});
workerHub.notify = function (message) {
$('#notifications').html(message);
};
workerHub.setProgress = function (progress) {
$('#progressbar').progressbar({ value: progress });
};
$.connection.hub.start();
}); </script>
</head>
<body>
<div id="progressbar" style="width: 200px;"></div>
<div id="notifications" style="width: 200px;"></div>
<button id="startWorkTrigger">Start work</button></body>
</html>
SignalR needs a backplane to scale. In a multi-server or multi-instance environment, communication sent from the client will only land on the server from which the originating call was made. If other users are actively connected to the application, but on different servers, the real-time communication won’t cross the servers. Click to play first animation.
If your application needs to run in a multiple-instance manner, a backplane is necessary. Click to fade in the backplane
Now that the backplane has been added to the architecture, the server or instances nodes can transmit data between the other servers or instances, enabling load-balanced real-time communication. Click to play the animation showing multi-server communication