This repository has been archived by the owner on Aug 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
18.01-Client_Server
42 lines (36 loc) · 1.89 KB
/
18.01-Client_Server
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
ARQUITETURA CLIENTE-SERVIDOR
==============================
Em geral, as formas que colocamos na arquitetura da última aula mantém o
ESTADO salvo dentro do hash dos labels. Porém, essa é uma forma, muitas
vezes, pouco eficiente: um usuário pode demorar para responder, ou pode
recarregar uma página web, resolicitar, etc.
Duas soluções, que mantém o estado fora do servidor, são possíveis:
* Manter o estado na aplicação
Usando variáveis escondidas, que não aparecem numa página web, é
possível enviar dados e/ou ações pela rede. Este protocolo é SEM
ESTADO: o protocolo não muda de acordo com o que está sendo
transferido. Ele apenas transfere informação de um ponto a outro.
O estado está nas aplicações (ações feitas), não no protocolo.
Nesse caso, não temos uma tabela que armazena dados/ações. O que
precisa ser feito é enviado dentro do protocolo.
* Manter o estado no cliente
Usamos o conceito de "cookies". Arquivos disponíveis no navegador
do usuário e que um dado site pode editar. Ele o usa para guardar
as informações dentro do cliente, no momento em que submete um
formulário para o servidor. O servidor pode, então, usar estes dados
SALVOS no cliente para continuar as ações.
; cookies
(define cookie '-100)
(define (read-number/suspend "\nFirst number (cookie)"
(lambda (v1)
(begin
(set! cookie v1)
(read-number/suspend "\nSecond number (cookie)"
(lambda (v2) (display (+ cookie v2)))
)))
))
Este é um exemplo de transimissão de informações chamado
continuation passing style (CPS). Ele consiste, primariamente, de
quebrar uma ação numa sequência de passos. Dado um passo i, ele
executa a computação correspondente a ele e depois envia o restante
da operação i+1 para ser executada depois.