<s>
Comet	B-General_Concept
is	O
a	O
web	B-Application
application	I-Application
model	O
in	O
which	O
a	O
long-held	O
HTTPS	B-Protocol
request	O
allows	O
a	O
web	B-Application
server	I-Application
to	O
push	B-General_Concept
data	O
to	O
a	O
browser	B-Application
,	O
without	O
the	O
browser	B-Application
explicitly	O
requesting	O
it	O
.	O
</s>
<s>
Comet	B-General_Concept
is	O
an	O
umbrella	O
term	O
,	O
encompassing	O
multiple	O
techniques	O
for	O
achieving	O
this	O
interaction	O
.	O
</s>
<s>
All	O
these	O
methods	O
rely	O
on	O
features	O
included	O
by	O
default	O
in	O
browsers	B-Application
,	O
such	O
as	O
JavaScript	B-Language
,	O
rather	O
than	O
on	O
non-default	O
plugins	O
.	O
</s>
<s>
The	O
Comet	B-General_Concept
approach	O
differs	O
from	O
the	O
original	O
model	O
of	O
the	O
web	O
,	O
in	O
which	O
a	O
browser	B-Application
requests	O
a	O
complete	O
web	O
page	O
at	O
a	O
time	O
.	O
</s>
<s>
The	O
use	O
of	O
Comet	B-General_Concept
techniques	O
in	O
web	O
development	O
predates	O
the	O
use	O
of	O
the	O
word	O
Comet	B-General_Concept
as	O
a	O
neologism	O
for	O
the	O
collective	O
techniques	O
.	O
</s>
<s>
Ajax	B-General_Concept
Push	I-General_Concept
,	O
</s>
<s>
The	O
term	O
Comet	B-General_Concept
is	O
not	O
an	O
acronym	O
,	O
but	O
was	O
coined	O
by	O
Alex	O
Russell	O
in	O
his	O
2006	O
blog	O
post	O
Comet	B-General_Concept
:	O
Low	O
Latency	O
Data	O
for	O
the	O
Browser	B-Application
.	O
</s>
<s>
In	O
recent	O
years	O
,	O
the	O
standardisation	O
and	O
widespread	O
support	O
of	O
WebSocket	B-Protocol
and	O
Server-sent	B-Language
events	I-Language
has	O
rendered	O
the	O
Comet	B-General_Concept
model	O
obsolete	O
.	O
</s>
<s>
The	O
ability	O
to	O
embed	O
Java	B-Application
applets	I-Application
into	O
browsers	B-Application
(	O
starting	O
with	O
Netscape	O
Navigator	O
2.0	O
in	O
March	O
1996	O
)	O
made	O
two-way	O
sustained	O
communications	O
possible	O
,	O
using	O
a	O
raw	O
TCP	B-Protocol
socket	O
to	O
communicate	O
between	O
the	O
browser	B-Application
and	O
the	O
server	O
.	O
</s>
<s>
This	O
socket	O
can	O
remain	O
open	O
as	O
long	O
as	O
the	O
browser	B-Application
is	O
at	O
the	O
document	O
hosting	O
the	O
applet	O
.	O
</s>
<s>
The	O
very	O
first	O
application	O
using	O
browser-to-browser	O
communications	O
was	O
Tango	O
Interactive	O
,	O
implemented	O
in	O
1996	O
–	O
98	O
at	O
the	O
Northeast	O
Parallel	O
Architectures	O
Center	O
(	O
)	O
at	O
Syracuse	O
University	O
using	O
DARPA	O
funding	O
.	O
</s>
<s>
The	O
first	O
set	O
of	O
Comet	B-General_Concept
implementations	O
date	O
back	O
to	O
2000	O
,	O
with	O
the	O
Pushlets	B-General_Concept
,	O
Lightstreamer	B-Application
,	O
and	O
KnowNow	O
projects	O
.	O
</s>
<s>
Pushlets	B-General_Concept
,	O
a	O
framework	O
created	O
by	O
Just	O
van	O
den	O
Broecke	O
,	O
was	O
one	O
of	O
the	O
first	O
open	O
source	O
implementations	O
.	O
</s>
<s>
Pushlets	B-General_Concept
were	O
based	O
on	O
server-side	O
Java	O
servlets	O
,	O
and	O
a	O
client-side	O
JavaScript	B-Language
library	O
.	O
</s>
<s>
Bang	O
Networks	O
a	O
Silicon	O
Valley	O
start-up	O
backed	O
by	O
Netscape	B-Protocol
co-founder	O
Marc	O
Andreessen	O
had	O
a	O
lavishly-financed	O
attempt	O
to	O
create	O
a	O
real-time	O
push	B-General_Concept
standard	O
for	O
the	O
entire	O
web	O
.	O
</s>
<s>
In	O
April	O
2001	O
,	O
Chip	O
Morningstar	O
began	O
developing	O
a	O
Java-based	O
(	O
J2SE	O
)	O
web	B-Application
server	I-Application
which	O
used	O
two	O
HTTP	B-Protocol
sockets	O
to	O
keep	O
open	O
two	O
communications	O
channels	O
between	O
the	O
custom	O
HTTP	B-Application
server	I-Application
he	O
designed	O
and	O
a	O
client	O
designed	O
by	O
Douglas	O
Crockford	O
;	O
a	O
functioning	O
demo	O
system	O
existed	O
as	O
of	O
June	O
2001	O
.	O
</s>
<s>
The	O
server	O
and	O
client	O
used	O
a	O
messaging	B-Protocol
format	O
that	O
the	O
founders	O
of	O
State	O
Software	O
,	O
Inc	O
.	O
assented	O
to	O
coin	O
as	O
JSON	B-General_Concept
following	O
Crockford	O
's	O
suggestion	O
.	O
</s>
<s>
The	O
entire	O
system	O
,	O
the	O
client	O
libraries	O
,	O
the	O
messaging	B-Protocol
format	O
known	O
as	O
JSON	B-General_Concept
and	O
the	O
server	O
,	O
became	O
the	O
State	O
Application	O
Framework	O
,	O
parts	O
of	O
which	O
were	O
sold	O
and	O
used	O
by	O
Sun	O
Microsystems	O
,	O
Amazon.com,	O
EDS	O
and	O
Volkswagen	O
.	O
</s>
<s>
In	O
March	O
2006	O
,	O
software	B-General_Concept
engineer	I-General_Concept
Alex	O
Russell	O
coined	O
the	O
term	O
Comet	B-General_Concept
in	O
a	O
post	O
on	O
his	O
personal	O
blog	O
.	O
</s>
<s>
The	O
new	O
term	O
was	O
a	O
play	O
on	O
Ajax	B-General_Concept
(	O
Ajax	B-General_Concept
and	O
Comet	B-General_Concept
both	O
being	O
common	O
household	O
cleaners	O
in	O
the	O
USA	O
)	O
.	O
</s>
<s>
In	O
2006	O
,	O
some	O
applications	O
exposed	O
those	O
techniques	O
to	O
a	O
wider	O
audience	O
:	O
Meebo	B-Protocol
’s	O
multi-protocol	O
web-based	B-Application
chat	O
application	O
enabled	O
users	O
to	O
connect	O
to	O
AOL	B-Protocol
,	O
Yahoo	B-Application
,	O
and	O
Microsoft	B-Protocol
chat	O
platforms	O
through	O
the	O
browser	B-Application
;	O
Google	B-Application
added	O
web-based	B-Application
chat	O
to	O
Gmail	B-Application
;	O
JotSpot	B-Application
,	O
a	O
startup	O
since	O
acquired	O
by	O
Google	B-Application
,	O
built	O
Comet-based	O
real-time	O
collaborative	O
document	O
editing	O
.	O
</s>
<s>
New	O
Comet	B-General_Concept
variants	O
were	O
created	O
,	O
such	O
as	O
the	O
Java-based	O
ICEfaces	B-Language
JSF	B-Language
framework	O
(	O
although	O
they	O
prefer	O
the	O
term	O
"	O
Ajax	B-General_Concept
Push	I-General_Concept
"	O
)	O
.	O
</s>
<s>
Others	O
that	O
had	O
previously	O
used	O
Java-applet	O
based	O
transports	O
switched	O
instead	O
to	O
pure-JavaScript	O
implementations	O
.	O
</s>
<s>
Comet	B-General_Concept
applications	O
attempt	O
to	O
eliminate	O
the	O
limitations	O
of	O
the	O
page-by-page	O
web	O
model	O
and	O
traditional	O
polling	B-General_Concept
by	O
offering	O
two-way	O
sustained	O
interaction	O
,	O
using	O
a	O
persistent	O
or	O
long-lasting	O
HTTP	B-Protocol
connection	O
between	O
the	O
server	O
and	O
the	O
client	O
.	O
</s>
<s>
Since	O
browsers	B-Application
and	O
proxies	O
are	O
not	O
designed	O
with	O
server	O
events	O
in	O
mind	O
,	O
several	O
techniques	O
to	O
achieve	O
this	O
have	O
been	O
developed	O
,	O
each	O
with	O
different	O
benefits	O
and	O
drawbacks	O
.	O
</s>
<s>
The	O
biggest	O
hurdle	O
is	O
the	O
HTTP	B-Protocol
1.1	I-Protocol
specification	O
,	O
which	O
states	O
"	O
this	O
specification	O
...	O
encourages	O
clients	O
to	O
be	O
conservative	O
when	O
opening	O
multiple	O
connections	O
"	O
.	O
</s>
<s>
Therefore	O
,	O
holding	O
one	O
connection	O
open	O
for	O
real-time	O
events	O
has	O
a	O
negative	O
impact	O
on	O
browser	B-Application
usability	O
:	O
the	O
browser	B-Application
may	O
be	O
blocked	O
from	O
sending	O
a	O
new	O
request	O
while	O
waiting	O
for	O
the	O
results	O
of	O
a	O
previous	O
request	O
,	O
e.g.	O
,	O
a	O
series	O
of	O
images	O
.	O
</s>
<s>
This	O
can	O
be	O
worked	O
around	O
by	O
creating	O
a	O
distinct	O
hostname	B-Protocol
for	O
real-time	O
information	O
,	O
which	O
is	O
an	O
alias	O
for	O
the	O
same	O
physical	O
server	O
.	O
</s>
<s>
Specific	O
methods	O
of	O
implementing	O
Comet	B-General_Concept
fall	O
into	O
two	O
major	O
categories	O
:	O
streaming	O
and	O
long	O
polling	B-General_Concept
.	O
</s>
<s>
An	O
application	O
using	O
streaming	O
Comet	B-General_Concept
opens	O
a	O
single	O
persistent	B-Protocol
connection	I-Protocol
from	O
the	O
client	B-Application
browser	I-Application
to	O
the	O
server	O
for	O
all	O
Comet	B-General_Concept
events	O
.	O
</s>
<s>
Specific	O
techniques	O
for	O
accomplishing	O
streaming	O
Comet	B-General_Concept
include	O
the	O
following	O
:	O
</s>
<s>
A	O
basic	O
technique	O
for	O
dynamic	O
web	B-Application
application	I-Application
is	O
to	O
use	O
a	O
hidden	O
iframe	O
HTML	O
element	O
(	O
an	O
inline	O
frame	O
,	O
which	O
allows	O
a	O
website	O
to	O
embed	O
one	O
HTML	O
document	O
inside	O
another	O
)	O
.	O
</s>
<s>
This	O
invisible	O
iframe	O
is	O
sent	O
as	O
a	O
chunked	B-Protocol
block	O
,	O
which	O
implicitly	O
declares	O
it	O
as	O
infinitely	O
long	O
(	O
sometimes	O
called	O
"	O
forever	O
frame	O
"	O
)	O
.	O
</s>
<s>
As	O
events	O
occur	O
,	O
the	O
iframe	O
is	O
gradually	O
filled	O
with	O
script	O
tags	O
,	O
containing	O
JavaScript	B-Language
to	O
be	O
executed	O
in	O
the	O
browser	B-Application
.	O
</s>
<s>
Because	O
browsers	B-Application
render	O
HTML	O
pages	O
incrementally	O
,	O
each	O
script	O
tag	O
is	O
executed	O
as	O
it	O
is	O
received	O
.	O
</s>
<s>
Some	O
browsers	B-Application
require	O
a	O
specific	O
minimum	O
document	O
size	O
before	O
parsing	O
and	O
execution	O
is	O
started	O
,	O
which	O
can	O
be	O
obtained	O
by	O
initially	O
sending	O
1	O
–	O
2	O
kB	O
of	O
padding	O
spaces	O
.	O
</s>
<s>
One	O
benefit	O
of	O
the	O
iframes	O
method	O
is	O
that	O
it	O
works	O
in	O
every	O
common	O
browser	B-Application
.	O
</s>
<s>
The	O
XMLHttpRequest	B-Protocol
(	O
XHR	B-Protocol
)	O
object	O
,	O
a	O
tool	O
used	O
by	O
Ajax	B-General_Concept
applications	O
for	O
browser	B-Application
–	O
server	O
communication	O
,	O
can	O
also	O
be	O
pressed	O
into	O
service	O
for	O
server	O
–	O
browser	B-Application
Comet	B-General_Concept
messaging	B-Protocol
by	O
generating	O
a	O
custom	O
data	O
format	O
for	O
an	O
XHR	B-Protocol
response	O
,	O
and	O
parsing	O
out	O
each	O
event	O
using	O
browser-side	O
JavaScript	B-Language
;	O
relying	O
only	O
on	O
the	O
browser	B-Application
firing	O
the	O
onreadystatechange	O
callback	O
each	O
time	O
it	O
receives	O
new	O
data	O
.	O
</s>
<s>
None	O
of	O
the	O
above	O
streaming	O
transports	O
work	O
across	O
all	O
modern	O
browsers	B-Application
without	O
negative	O
side-effects	O
.	O
</s>
<s>
This	O
forces	O
Comet	B-General_Concept
developers	O
to	O
implement	O
several	O
complex	O
streaming	O
transports	O
,	O
switching	O
between	O
them	O
depending	O
on	O
the	O
browser	B-Application
.	O
</s>
<s>
Consequently	O
,	O
many	O
Comet	B-General_Concept
applications	O
use	O
long	O
polling	B-General_Concept
,	O
which	O
is	O
easier	O
to	O
implement	O
on	O
the	O
browser	B-Application
side	O
,	O
and	O
works	O
,	O
at	O
minimum	O
,	O
in	O
every	O
browser	B-Application
that	O
supports	O
XHR	B-Protocol
.	O
</s>
<s>
As	O
the	O
name	O
suggests	O
,	O
long	O
polling	B-General_Concept
requires	O
the	O
client	O
to	O
poll	O
the	O
server	O
for	O
an	O
event	O
(	O
or	O
set	O
of	O
events	O
)	O
.	O
</s>
<s>
The	O
browser	B-Application
makes	O
an	O
Ajax-style	O
request	O
to	O
the	O
server	O
,	O
which	O
is	O
kept	O
open	O
until	O
the	O
server	O
has	O
new	O
data	O
to	O
send	O
to	O
the	O
browser	B-Application
,	O
which	O
is	O
sent	O
to	O
the	O
browser	B-Application
in	O
a	O
complete	O
response	O
.	O
</s>
<s>
The	O
browser	B-Application
initiates	O
a	O
new	O
long	O
polling	B-General_Concept
request	O
in	O
order	O
to	O
obtain	O
subsequent	O
events	O
.	O
</s>
<s>
compares	O
long	O
polling	B-General_Concept
and	O
HTTP	B-General_Concept
streaming	I-General_Concept
.	O
</s>
<s>
Specific	O
technologies	O
for	O
accomplishing	O
long-polling	O
include	O
the	O
following	O
:	O
</s>
<s>
For	O
the	O
most	O
part	O
,	O
XMLHttpRequest	B-Protocol
long	O
polling	B-General_Concept
works	O
like	O
any	O
standard	O
use	O
of	O
XHR	B-Protocol
.	O
</s>
<s>
The	O
browser	B-Application
makes	O
an	O
asynchronous	O
request	O
of	O
the	O
server	O
,	O
which	O
may	O
wait	O
for	O
data	O
to	O
be	O
available	O
before	O
responding	O
.	O
</s>
<s>
The	O
response	O
can	O
contain	O
encoded	O
data	O
(	O
typically	O
XML	B-Protocol
or	O
JSON	B-General_Concept
)	O
or	O
Javascript	B-Language
to	O
be	O
executed	O
by	O
the	O
client	O
.	O
</s>
<s>
At	O
the	O
end	O
of	O
the	O
processing	O
of	O
the	O
response	O
,	O
the	O
browser	B-Application
creates	O
and	O
sends	O
another	O
XHR	B-Protocol
,	O
to	O
await	O
the	O
next	O
event	O
.	O
</s>
<s>
Thus	O
the	O
browser	B-Application
always	O
keeps	O
a	O
request	O
outstanding	O
with	O
the	O
server	O
,	O
to	O
be	O
answered	O
as	O
each	O
event	O
occurs	O
.	O
</s>
<s>
While	O
any	O
Comet	B-General_Concept
transport	O
can	O
be	O
made	O
to	O
work	O
across	O
subdomains	B-Protocol
,	O
none	O
of	O
the	O
above	O
transports	O
can	O
be	O
used	O
across	O
different	O
second-level	B-Protocol
domains	I-Protocol
(	O
SLDs	O
)	O
,	O
due	O
to	O
browser	B-Application
security	O
policies	O
designed	O
to	O
prevent	O
cross-site	O
scripting	O
attacks	O
.	O
</s>
<s>
That	O
is	O
,	O
if	O
the	O
main	O
web	O
page	O
is	O
served	O
from	O
one	O
SLD	O
,	O
and	O
the	O
Comet	B-General_Concept
server	O
is	O
located	O
at	O
another	O
SLD	O
(	O
which	O
does	O
not	O
have	O
cross-origin	B-General_Concept
resource	I-General_Concept
sharing	I-General_Concept
enabled	O
)	O
,	O
Comet	B-General_Concept
events	O
cannot	O
be	O
used	O
to	O
modify	O
the	O
HTML	O
and	O
DOM	O
of	O
the	O
main	O
page	O
,	O
using	O
those	O
transports	O
.	O
</s>
<s>
This	O
problem	O
can	O
be	O
sidestepped	O
by	O
creating	O
a	O
proxy	B-Application
server	I-Application
in	O
front	O
of	O
one	O
or	O
both	O
sources	O
,	O
making	O
them	O
appear	O
to	O
originate	O
from	O
the	O
same	O
domain	O
.	O
</s>
<s>
Unlike	O
iframes	O
or	O
XMLHttpRequest	B-Protocol
objects	O
,	O
script	O
tags	O
can	O
be	O
pointed	O
at	O
any	O
URI	B-Protocol
,	O
and	O
JavaScript	B-Language
code	O
in	O
the	O
response	O
will	O
be	O
executed	O
in	O
the	O
current	O
HTML	O
document	O
.	O
</s>
<s>
This	O
creates	O
a	O
potential	O
security	O
risk	O
for	O
both	O
servers	O
involved	O
,	O
though	O
the	O
risk	O
to	O
the	O
data	O
provider	O
(	O
in	O
our	O
case	O
,	O
the	O
Comet	B-General_Concept
server	O
)	O
can	O
be	O
avoided	O
using	O
JSONP	B-General_Concept
.	O
</s>
<s>
A	O
long-polling	O
Comet	B-General_Concept
transport	O
can	O
be	O
created	O
by	O
dynamically	O
creating	O
script	O
elements	O
,	O
and	O
setting	O
their	O
source	O
to	O
the	O
location	O
of	O
the	O
Comet	B-General_Concept
server	O
,	O
which	O
then	O
sends	O
back	O
JavaScript	B-Language
(	O
or	O
JSONP	B-General_Concept
)	O
with	O
some	O
event	O
as	O
its	O
payload	O
.	O
</s>
<s>
Each	O
time	O
the	O
script	O
request	O
is	O
completed	O
,	O
the	O
browser	B-Application
opens	O
a	O
new	O
one	O
,	O
just	O
as	O
in	O
the	O
XHR	B-Protocol
long	O
polling	B-General_Concept
case	O
.	O
</s>
<s>
This	O
method	O
has	O
the	O
advantage	O
of	O
being	O
cross-browser	O
while	O
still	O
allowing	O
cross-domain	O
implementations	O
.	O
</s>
<s>
Browser-native	O
technologies	O
are	O
inherent	O
in	O
the	O
term	O
Comet	B-General_Concept
.	O
</s>
<s>
Attempts	O
to	O
improve	O
non-polling	O
HTTP	B-Protocol
communication	O
have	O
come	O
from	O
multiple	O
sides	O
:	O
</s>
<s>
The	O
HTML	B-Application
5	I-Application
draft	O
specification	O
produced	O
by	O
the	O
Web	B-Language
Hypertext	I-Language
Application	I-Language
Technology	I-Language
Working	I-Language
Group	I-Language
(	O
WHATWG	B-Language
)	O
specifies	O
so	O
called	O
server-sent	B-Language
events	I-Language
,	O
which	O
defines	O
a	O
new	O
JavaScript	B-Language
interface	O
EventSource	O
and	O
a	O
new	O
MIME	O
type	O
text/event	O
-stream	O
.	O
</s>
<s>
All	O
major	O
browsers	B-Application
except	O
Microsoft	B-Protocol
Internet	O
Explorer	O
include	O
this	O
technology	O
.	O
</s>
<s>
The	O
HTML	B-Application
5	I-Application
WebSocket	B-Protocol
API	I-Protocol
working	O
draft	O
specifies	O
a	O
method	O
for	O
creating	O
a	O
persistent	B-Protocol
connection	I-Protocol
with	O
a	O
server	O
and	O
receiving	O
messages	O
via	O
an	O
onmessage	O
callback	O
.	O
</s>
<s>
The	O
Bayeux	O
protocol	O
by	O
the	O
Dojo	B-General_Concept
Foundation	I-General_Concept
.	O
</s>
<s>
It	O
leaves	O
browser-specific	O
transports	O
in	O
place	O
,	O
and	O
defines	O
a	O
higher-level	O
protocol	O
for	O
communication	O
between	O
browser	B-Application
and	O
server	O
,	O
with	O
the	O
aim	O
of	O
allowing	O
re-use	O
of	O
client-side	O
JavaScript	B-Language
code	O
with	O
multiple	O
Comet	B-General_Concept
servers	O
,	O
and	O
allowing	O
the	O
same	O
Comet	B-General_Concept
server	O
to	O
communicate	O
with	O
multiple	O
client-side	O
JavaScript	B-Language
implementations	O
.	O
</s>
<s>
The	O
BOSH	B-Protocol
protocol	O
by	O
the	O
XMPP	O
standards	O
foundation	O
.	O
</s>
<s>
It	O
emulates	O
a	O
bidirectional	O
stream	O
between	O
browser	B-Application
and	O
server	O
by	O
using	O
two	O
synchronous	O
HTTP	B-Protocol
connections	O
.	O
</s>
<s>
The	O
JSONRequest	O
object	O
,	O
proposed	O
by	O
Douglas	O
Crockford	O
,	O
would	O
be	O
an	O
alternative	O
to	O
the	O
XHR	B-Protocol
object	O
.	O
</s>
<s>
Use	O
of	O
plugins	O
,	O
such	O
as	O
Java	B-Application
applets	I-Application
or	O
the	O
proprietary	O
Adobe	B-Operating_System
Flash	I-Operating_System
(	O
using	O
RTMP	B-Operating_System
protocol	O
for	O
data	O
streaming	O
to	O
Flash	O
applications	O
)	O
.	O
</s>
<s>
Google	B-Application
announced	O
a	O
new	O
Channel	O
API	O
for	O
Google	B-Application
App	I-Application
Engine	I-Application
,	O
implementing	O
a	O
Comet-like	O
API	O
with	O
the	O
help	O
of	O
a	O
client	O
JavaScript	B-Language
library	O
on	O
the	O
browser	B-Application
.	O
</s>
