Professional Documents
Culture Documents
Ngoc Dao
Do you know WebSocket?
WebSocket
<script>
var sock = new WebSocket('ws:!o"ain"y#pre$i%'&'
sock.onopen = $unction(& (
conso)e*)og('open'&'
+'
sock.onmessage = $unction(e& (
conso)e*)og('"essage', e*!ata&'
+'
sock.onclose = $unction(& (
conso)e*)og('c)ose'&'
+'
<script>
Server can pus- !ata
to browsers w-en it wants
WebSocket
New browsers are re.uire!:
Internet /%p)orer: 01
2ire$o%: 3
4-ro"e: 5
Sa$ari: 6
7pera: 08*01
SockJS
>e.uires
4)ient si!e: sock=s*=s
Server si!e: SockJS server si!e )ibrary
WebSocket vs SockJS
WebSocket
<script>
var sock = new WebSocket('ws:!o"ain"y#ws'&'
sock.onopen = $unction(& (
conso)e*)og('open'&'
+'
sock.onmessage = $unction(e& (
conso)e*)og('"essage', e*!ata&'
+'
sock.onclose = $unction(& (
conso)e*)og('c)ose'&'
+'
<script>
SockJS
<script>
var sock = new SockJS('-ttp:!o"ain"y#pre$i%'&'
sock.onopen = $unction(& (
conso)e*)og('open'&'
+'
sock.onmessage = $unction(e& (
conso)e*)og('"essage', e*!ata&'
+'
sock.onclose = $unction(& (
conso)e*)og('c)ose'&'
+'
<script>
?inks
4)ient si!e:
<script src=@-ttp:c!n*sock=s*orgsock=s:1*A*"in*=s@><script>
-ttps:git-ub*co"sock=ssock=s:c)ient
Server si!e:
No!e*=s: -ttps:git-ub*co"sock=ssock=s:no!e
>uby: -ttps:git-ub*co"sock=ssock=s:ruby
9yt-on: -ttps:git-ub*co"BrJoessock=s:torna!o
JCB:
-ttps:git-ub*co"vert:%vert*%
-ttps:git-ub*co"ngoc!aot-an-%itru"
etc*
?inks
4)ient si!e:
<script src=@-ttp:c!n*sock=s*orgsock=s:1*A*"in*=s@><script>
-ttps:git-ub*co"sock=ssock=s:c)ient
Server si!e:
No!e*=s: -ttps:git-ub*co"sock=ssock=s:no!e
>uby: -ttps:git-ub*co"sock=ssock=s:ruby
9yt-on: -ttps:git-ub*co"BrJoessock=s:torna!o
JCB:
-ttps:git-ub*co"vert:%vert*%
-ttps:git-ub*co"ngoc!aot-an-%itru"
etc*
De"o
-ttps:git-ub*co"sock=ssock=s:no!etree"astere%a"p)esec-o
git c)one git:git-ub*co"sock=ssock=s:no!e*git
c! sock=s:no!ee%a"p)esec-o
np" insta))
no!e server*=s
SockJS protoco)
I$ you want to i"p)e"ent a server si!e $or SockJS,
or =ust want to know -ow SockJS works:
-ttps:git-ub*co"sock=ssock=s:protoco)
-ttp:sock=s*git-ub*co"sock=s:protoco)sock=s:protoco):1*A*A*-t")
SockJS vs Socket*I7
Socket*I7 D SockJS E F