ANDRÉ PAULOVICH IVAN PAULOVICH
João Pessoa...
Paraíba – Oxente!
Belo Horizonte...
Minas Gerais – Uai!
www.100loop.com
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
HTTP != “Tempo real”
Contras
Atraso nas atualizações
Sobrecarrega o server com requests
desnecessários
Prós
Sem atraso nas respostas
Múltiplos requests
Contras
Baixa carga no servidor
Existem técnicas mais rápidas
Suportado por vários Browsers
Prós
Suportado por vários Browsers
Contras
Contras Problemas com peculiaridades de
cada Browser.
Muito difícil de tratar os erros
Prós
Conexão persistente.
Não necessidta de um protocolo especial
implementado no servidor.
Contras
Nâo é suportado pelo Internet Explorer.
Trabalha apenas na direção:
Server > Client.
Prós
Conexão persistente nas duas direções.
Melhor performance.
Contras
Requer protocolo WEB SOCKET IE 10 e demais
browsers (versões atualizadas)
Requer protocolo WEB SOCKET no Servidor (IIS8)
E agora...
Para onde seguir?
David Fowler
@davidfowl
Damian Edwards
@damianedwards
Desenvolvida por funcionários da
Microsoft da equipe ASP.NET
Combinando uma biblioteca ASP
.NET no lado do servidor e uma
biblioteca JavaScript do lado
cliente
Transportes
Conexiones persistentes
Long polling
Server-sent
events
Forever
frame
WebSockets
Hubs
Protocolos internet
Abstracción
Aplicação .NET (Server Side)
HUB API
API de Conexão Persistente
Transportes
HTML5 Comet
Web Sockets
Server Sent Events
Forever Frame
Ajax Long Polling
Browser (Client Side)
HUB API
API de Conexão Persistente
Transportes
Browser (Client Side)
HUB API
API de Conexão Persistente
Transportes
Browser (Client Side)
HUB API
API de Conexão Persistente
Transportes
Servidor
Clientes
Servidor (Conexión persistente)Cliente (javascript)
var conn = $.connection(“MyConn”);
conn.start();
conn.send(“hi, all!”);
conn.receive(function(text) {
$(“#log”)
.append(“<li>”+text+”</li>”);
});
class MyConn: PersistentConnection
{
override Task OnConnectedAsync() { … }
override Task OnReceivedAsync(string data)
{
return Connection.Broadcast(data);
}
override Task OnDisconnectAsync() { ... }
}
Servidor
(Hub)
Cliente (javascript)
var chat = $.connection.chatHub;
$.connection.hub.start();
chat.enviar(“hi, all!”);
chat.recibir = function(text) {
$(“#log”)
.append(“<li>”+text+”</li>”);
};
Proxy
class ChatHub: Hub
{
public void enviar(string text)
{
Clients.recibir(text);
}
}
•
JQuery
WinRT
Native
.NET
Android
(via Mono)
WP7 Silverlight
CLIENTES
iOS
HOSTS
1.
2.
PM> Install-Package Microsoft.AspNet.SignalR
PUBLIC CLASS SHAPEHUB : HUB
{
//
// RECEBE MENSAGENS DO CLIENTE
//
PUBLIC VOID MOVESHAPE(INT X, INT Y)
{
//
// ENVIA MENSAGENS PARA O CLIENTE
//
THIS.CLIENTS.OTHERS.UPDATESHAPE(X, Y);
}
}
 Simples definição do Hub
 Implementação dos
métodos
 Uso intensivo de Anonymous
Methods
<SCRIPT TYPE="TEXT/JAVASCRIPT">
$(FUNCTION () {
VAR SHAPE = $("#SHAPE");
$.CONNECTION.HUB.START().DONE(FUNCTION () {
SHAPE.DRAGGABLE({
DRAG: FUNCTION () {
// ENVIA A NOVA POSIÇÃO PARA O SERVIDOR
$.CONNECTION.SHAPEHUB.SERVER.MOVESHAPE(
SHAPE.POSITION().LEFT,
SHAPE.POSITION().TOP);
}
});
});
// RECEBE AS MENSAGENS DO SERVIDOR
$.CONNECTION.SHAPEHUB.CLIENT.UPDATESHAPE = FUNCTION (X, Y) {
SHAPE.ANIMATE({ LEFT: X, TOP: Y }, { QUEUE: FALSE });
}
});
</SCRIPT>
 Implementação dos
métodos no cliente “.client”
 Pode chamar métodos no
servidor “.server”
•
•
 Backplane
 Azure Service Bus
 Requisitos Websocket no Azure Websites
 ASP.NET 4.5
 Habilitar no painel
•
HTTP://SHOOTR.SIGNALR.NET/
•
HTTPS://JABBR.NET
• HTTPS://TWITTER.COM/DAMIANEDWARDS
• HTTP://ASP.NET/SIGNALR
• HTTP://GIFTHUB.COM/SIGNALR/SIGNALR
• HTTP://100LOOP.COM
• HTTP://GIFTHUB.COM/IVANPAULOVICH/ASPNETCONF
MANTENHA CONTATO NO WWW.100LOOP.COM
ANDRÉ PAULOVICH PAULOVICH@100LOOP.COM
IVAN PAULOVICH - IVAN@100LOOP.COM

Construindo Apps Com SignalR

Notas do Editor

  • #13 Regular http:A client requests a webpage from a server.The server calculates the responseThe server sends the response to the client.Referência:http://stackoverflow.com/questions/11077857/what-are-long-polling-websockets-server-sent-events-sse-and-comet
  • #14 AJAX Polling:A client requests a webpage from a server using regular http (see http above).The requested webpage executes javascript which requests a file from the server at regular intervals (e.g. 0.5 seconds).The server calculates each response and sends it back, just like normal http traffic.
  • #16 AJAX Long-Polling:A client requests a webpage from a server using regular http (see http above).The requested webpage executes javascript which requests a file from the server.The server does not immediately respond with the requested information but waits until there&apos;s new information available.When there&apos;s new information available, the server responds with the new information.The client receives the new information and immediately sends another request to the server, re-starting the process.
  • #18 HTML5 Server Sent Events (SSE) / EventSource:A client requests a webpage from a server using regular http (see http above).The requested webpage executes javascript which opens a connection to the server.The server sends an event to the client when there&apos;s new information available.real-time traffic from server to client, mostly that&apos;s what you&apos;ll needyou&apos;ll want to use a server that has an event loopnot possible to connect with a server from another domainIf you want to read more, I found thse (article), (article), (article), (tutorial) very useful.
  • #20 HTML5 Server Sent Events (SSE) / EventSource:A client requests a webpage from a server using regular http (see http above).The requested webpage executes javascript which opens a connection to the server.The server sends an event to the client when there&apos;s new information available.real-time traffic from server to client, mostly that&apos;s what you&apos;ll needyou&apos;ll want to use a server that has an event loopnot possible to connect with a server from another domainIf you want to read more, I found thse (article), (article), (article), (tutorial) very useful.
  • #22 HTML5 Websockets:A client requests a webpage from a server using regular http (see http above).The requested webpage executes javascript which opens a connection with the server.The server and the client can now send each other messages when new data (on either side) is available.real-time traffic from the server to the client and from the client to the serveryou&apos;ll want to use a server that has an event loopwith WebSockets it is possible to connect with a server from another domain.It is also possible to use a third party hosted websocket server, for example Pusher or others. This way you&apos;ll only have to implement the client side, which is very easy!If you want to read more, I found thse (article), (article) (tutorial) very useful.