Download Java EE 7 Development with WildFly

Transcript
GET/ticket-agency-websockets/ticketsHTTP/1.1
Upgrade:websocket
Connection:Upgrade
Host:localhost:8080
Origin:http://localhost:8080Pragma:no-cache
Cache-Control:no-cache
Sec-WebSocket-Key:TrjgyVjzLK4Lt5s8GzlFhA==
Sec-WebSocket-Version:13
Sec-WebSocket-Extensions:permessage-deflate;client_max_window_bits,xwebkit-deflate-frame
User-Agent:Mozilla/5.0(WindowsNT6.3;WOW64)AppleWebKit/537.36(KHTML,
likeGecko)Chrome/34.0.1847.116Safari/537.36
Cookie:[45byteswerestripped]
WecanseethattheclientrequestsanupgradeconnectionwithWebSocketasthetarget
protocolontheURL/ticket-agency-websockets/tickets.Itadditionallypasses
informationabouttherequestedversionandkey.
Iftheserversupportstherequestprotocolandalltherequireddataispassedbytheclient,
thenitwouldrespondwiththefollowingframe:
HTTP/1.1101SwitchingProtocols
X-Powered-By:Undertow1
Server:Wildfly8
Origin:http://localhost:8080
Upgrade:WebSocket
Sec-WebSocket-Accept:ZEAab1TcSQCmv8RsLHg4RL/TpHw=
Date:Sun,13Apr201417:04:00GMT
Connection:Upgrade
Sec-WebSocket-Location:ws://localhost:8080/ticket-agencywebsockets/tickets
Content-Length:0
Thestatuscodeoftheresponseis101(switchingprotocols)andwecanseethattheserver
isnowgoingtostartusingtheWebSocketprotocol.TheTCPconnectioninitiallyusedfor
theHTTPrequestisnowthebaseoftheWebSocketsessionandcanbeusedfor
transmissions.IftheclienttriestoaccessaURL,whichisonlyhandledbyanother
protocol,thentheservercanasktheclienttodoanupgraderequest.Theserverusesthe
426(upgraderequired)statuscodeinsuchcases.
Note
Theinitialconnectioncreationhassomeoverhead(becauseoftheHTTPframesthatare
exchangedbetweenthepeers),butafteritiscompleted,newmessageshaveonly2bytes
ofadditionalheaders.Thismeansthatwhenwehavealargenumberofsmallmessages,
WebSocketwillbeanorderofmagnitudefasterthanRESTprotocolssimplybecausethere
islessdatatotransmit!
IfyouarewonderingaboutthebrowsersupportofWebSockets,youcanlookitupat
http://caniuse.com/websockets.Allnewversionsofmajorbrowserscurrentlysupport
WebSockets;thetotalcoverageisestimated(atthetimeofwriting)at74percent.Youcan
seethisinthefollowingscreenshot: