ºÝºÝߣ

ºÝºÝߣShare a Scribd company logo
WebSocket

      ( )
    / MA        / TI
@ohmyzany, http://zany.kr
? ???? ?????
         TCP Socket ? ???? ??? ??(two-way communication)?
         ?? ?? ??.

         ?? ??(PUSH Technology)? ??.

         ?? W3C ? ?? ??? ?? ?.
                W3C Editor's Draft - 27 July, 2010

                W3C Working Draft - 22 December, 2009

         ?? ??? Chrome ?? Safari ? ? ??? ??.




WebSocket - http://zany.kr (@ohmyzany)                      2
? ??? ? ?????
         ? ??? long-polling (Comet; Reverse AJAX) ? ??.
                long-polling (Comet; Reverse AJAX) ??

                      ??????? ?? ?? ?, Connection ? ??? ??

                      ?? ???? ?? ??? ??? Connection ? ?? ???? Push ??
                      ? ??.

                      ?????? ??? ?? ?? ?? ??? ??? ??

                      ??? ???? ??? Connection ? ??.




WebSocket - http://zany.kr (@ohmyzany)                                  3
Ajax - Asynchronous JavaScript and XML




WebSocket - http://zany.kr (@ohmyzany)   4
Long-polling (Comet; Reverse AJAX)




WebSocket - http://zany.kr (@ohmyzany)   5
WebSocket W3C Editor's Draft
                 2010? 8? 10? ??, WebSocket Interface

      [Constructor(inDOMStringurl,inoptionalDOMStringprotocols)]                            ? 10 August, 2010 Editor¡¯s Draft
      [Constructor(inDOMStringurl,inoptionalDOMString[]protocols)]
      interfaceWebSocket{                                                                                                   ? ?? ? ??? Working Draft ?? ?? ??.
      readonlyattributeDOMStringurl;
                                                                                                                                            ? Working Draft : 22 December, 2009
      //readystate
      constunsignedshortCONNECTING=0;
      constunsignedshortOPEN=1;
      constunsignedshortCLOSING=2;
      constunsignedshortCLOSED=3;
      readonlyattributeunsignedshortreadyState;
      readonlyattributeunsignedlongbufferedAmount;

      //networking
      attributeFunctiononopen;
      attributeFunctiononmessage;
      attributeFunctiononerror;
      attributeFunctiononclose;
      readonlyattributeDOMStringprotocol;
      booleansend(inDOMStringdata);
      voidclose();
      };
      WebSocketimplementsEventTarget;



WebSocket - http://zany.kr (@ohmyzany)                                                                                                                                            6
WebSocket Interface
         Interface ??
                ???(Constructor)? 2?? ??? ??

                      ??? URL

                      ??? ???? (?????, ???? ??) - Optional

                             non-empty ASCII string.

                             only characters in the range U+0021 to U+007E




WebSocket - http://zany.kr (@ohmyzany)                                       7
WebSocket Interface
         Websocket ?? ?? - websocket() ???? ????...
                URL ????? host, port, resource name, secure ? ??

                      ???? ??, SYNTAX_ERR exception ? throw ?? ??.

                ????? 80 ?? ??, 443 ??? ?? ??? ??.

                      ??? ?? ?? ?? SECURITY_ERR exception throw.

                protocol ? ????? ?? ????, SYNTAX_ERR exception ?
                throw ?? ??.

                websocket ??? ?? (??? ???? readyState ???
                CONNECTING ??? ????)

                ??? ??? ?? ?? (host, port, resource name, secure,
                protocol)
WebSocket - http://zany.kr (@ohmyzany)                               8
WebSocket Interface
         readyState Attribute
                CONNECTING (0) : Connection ? ?? Established ?? ?? ??.

                OPEN (1) : ? ??? Established ? ??, ?? ??.

                CLOSING (2) : ??? ???? ?? ?.

                CLOSED (3) : ??? ??? ???.




WebSocket - http://zany.kr (@ohmyzany)                                   9
WebSocket Interface
         send(DOMString data) method
                ???? ??.

                readyState ? CONNECTING ? ??, INVALID_STATE_ERR exception.

                data ??? ??? ?? ?? ??, SYNTAX_ERR exception.




WebSocket - http://zany.kr (@ohmyzany)                                  10
WebSocket Interface
         close() method
                readySate ???? CLOSING, CLOSED ? ??, do nothing.

                ??? Established ? ?? ??, readyState ?? CLOSING ?? ??.

                ?? ?? ??? ?? ???? ?? ??, readyState ????
                CLOSING ?? ??.

                ??? ??, readyState ???? CLOSING ?? ??.




WebSocket - http://zany.kr (@ohmyzany)                             11
? ?? ??? ??
         phpwebsockets
                http://code.google.com/p/phpwebsockets/

         jWebSocket ( java)
                http://jwebsocket.org/

         web-socket-ruby (ruby)
                http://github.com/gimite/web-socket-ruby

         Socket-IO-node (node.js)
                http://github.com/LearnBoost/Socket.IO-node



WebSocket - http://zany.kr (@ohmyzany)                        12
jWebSocket
         jWebSocket ??
                ??? ???? ??? ??(bidirectional communication)? ?? ?
                ? ???.

                HTML5 ??? ????, ?????? ?????? ?? ??.

                Java/JavaScript ?? ??.

                ??? XHR(Xml Http Request)? Comet ???? ??.




WebSocket - http://zany.kr (@ohmyzany)                           13
jWebSocket
         jWebSocket ??
                jWebSocket Server (pure Java Based)

                      server-to-client (S2C) streaming solutions

                      server controlled (C2C) client-to-client-communication.

                jWebSocket Client (pure JavaScript Based)

                      multiple subprotocols

                      an optional user, session and timeout-management.

                      No plug-ins required

                jWebSocket FlashBridge

                      a Flash based WebSocket Wrapper (requires Flash plug-in)
WebSocket - http://zany.kr (@ohmyzany)                                           14
jWebSocket
         Infrastructure - Server




WebSocket - http://zany.kr (@ohmyzany)   15
jWebSocket
         Infrastructure - Client




WebSocket - http://zany.kr (@ohmyzany)   16
jWebSocket
         ?? ????

           Browser         Version                                         Comment

                              6.0.x
                                         ? Chrome includes native WebSockets since 4.0.249.
             Chrome           5.0.x
                            4.0.249+     ? Tested and verified by jWebSocket team 2010-02-28.


                                         ? Safari 5.x includes native WebSockets
                               5.x
              Safari                       - tested and verified by jWebSocket team 2010-06-08.
                               4.x
                                         ? Safari 4.x does not yet provide the WebSocket class.


                             4.0b1       ? Firefox 3.7a6 and 4.0b1 now include native WebSockets
             Firefox         3.7a6         - tested and verified by jWebSocket team 2010-07-14
                             3.0+        ? including new Security features (Sec-WebSocket-Key header processing)


           Opera with         9+
                                         ? Tested and verified by jWebSocket team 2010-03-28.
           FlashBridge        10+



WebSocket - http://zany.kr (@ohmyzany)                                                                             17
jWebSocket
         ?? ?? ??
                ?? ?? ????.

                Windows, Linux, Unix ?? ??.

         Prerequisites on the Server
                Java Runtime Environment (JRE) 1.5

                JAVA_HOME ?? ?? : Java Home Directory.

                JWEBSOCKET_HOME ?? ?? : jWebSocket Home Directory.

                Windows ????? java.exe ? PATH ? ???? ?? ?? ??.



WebSocket - http://zany.kr (@ohmyzany)                               18
jWebSocket
         ?? ?? ??
                ?? ?? ???? - jWebSocketServer-0.9.5.zip

                ??? ????? ?? ??

                Symbolic Link - /usr/local/jWebSocketServer

                JWEBSOCKET_HOME ?? ?? ?? - .bashrc or .bash_profile

     [root@zanyui-Mac-ProjWebSocket]#cpjWebSocketServer-0.9.5.zip/usr/local
     [root@zanyui-Mac-ProjWebSocket]#cd/usr/local
     [root@zanyui-Mac-ProjWebSocket]#unzipjWebSocketServer-0.9.5.zip
     [root@zanyui-Mac-ProjWebSocket]#ln-s/usr/local/jWebSocket-0.9.5/jWebSocketServer



WebSocket - http://zany.kr (@ohmyzany)                                                                                          19
jWebSocket
         ?? ??
                 ?? 2?? ?? ? ?? ??.

                        apache ? ??? ???? ??? ??.

                                $ apachectl start



       java-jar$JWEBSOCKET_HOME/libs/jWebSocketServer-0.9.5.jar
       java-jar$JWEBSOCKET_HOME/libs/jWebSocketServer-0.9.5.jarlogtarget=consoleloglevel=info




WebSocket - http://zany.kr (@ohmyzany)                                                                                                   20
jWebSocket
         ????? ??
                ????? ?? ?? ???? - jWebSocketClient-0.9.5.zip

                ??? ????? ?? ??? ?, apache ? ???? ?? ????
                ? ?????, ~/Sites/jWebSocketClient ? ?? ????? ?? ?
                ??? http://localhost/~user/jWebSocketClient ? ????.

                Apache Web Server 2.2.14 ??, ?? ???? ???? ??
                                     $vi/etc/apache2/httpd.conf
                                     IfModulealias_module/IfModule??????????
                                     #ZanyAdd
                                     Alias/jWebSocket/Volumes/MacData/Projects/websocket/jWebSocket


                                     Directory/Volumes/MacData/Projects/websocket/jWebSocket
                                     OptionsIndexesFollowSymLinksMultiViewsExecCGI
                                     AllowOverrideNone
                                     Orderallow,deny
                                     Allowfromall
                                     /Directory


WebSocket - http://zany.kr (@ohmyzany)                                                                                                               21
?? ? ?? ??
         WebSocket Interface.

         jWebSocket.




WebSocket - http://zany.kr (@ohmyzany)   22

More Related Content

HTML5 WebSocket ?? ??

  • 1. WebSocket ( ) / MA / TI @ohmyzany, http://zany.kr
  • 2. ? ???? ????? TCP Socket ? ???? ??? ??(two-way communication)? ?? ?? ??. ?? ??(PUSH Technology)? ??. ?? W3C ? ?? ??? ?? ?. W3C Editor's Draft - 27 July, 2010 W3C Working Draft - 22 December, 2009 ?? ??? Chrome ?? Safari ? ? ??? ??. WebSocket - http://zany.kr (@ohmyzany) 2
  • 3. ? ??? ? ????? ? ??? long-polling (Comet; Reverse AJAX) ? ??. long-polling (Comet; Reverse AJAX) ?? ??????? ?? ?? ?, Connection ? ??? ?? ?? ???? ?? ??? ??? Connection ? ?? ???? Push ?? ? ??. ?????? ??? ?? ?? ?? ??? ??? ?? ??? ???? ??? Connection ? ??. WebSocket - http://zany.kr (@ohmyzany) 3
  • 4. Ajax - Asynchronous JavaScript and XML WebSocket - http://zany.kr (@ohmyzany) 4
  • 5. Long-polling (Comet; Reverse AJAX) WebSocket - http://zany.kr (@ohmyzany) 5
  • 6. WebSocket W3C Editor's Draft 2010? 8? 10? ??, WebSocket Interface [Constructor(inDOMStringurl,inoptionalDOMStringprotocols)] ? 10 August, 2010 Editor¡¯s Draft [Constructor(inDOMStringurl,inoptionalDOMString[]protocols)] interfaceWebSocket{ ? ?? ? ??? Working Draft ?? ?? ??. readonlyattributeDOMStringurl; ? Working Draft : 22 December, 2009 //readystate constunsignedshortCONNECTING=0; constunsignedshortOPEN=1; constunsignedshortCLOSING=2; constunsignedshortCLOSED=3; readonlyattributeunsignedshortreadyState; readonlyattributeunsignedlongbufferedAmount; //networking attributeFunctiononopen; attributeFunctiononmessage; attributeFunctiononerror; attributeFunctiononclose; readonlyattributeDOMStringprotocol; booleansend(inDOMStringdata); voidclose(); }; WebSocketimplementsEventTarget; WebSocket - http://zany.kr (@ohmyzany) 6
  • 7. WebSocket Interface Interface ?? ???(Constructor)? 2?? ??? ?? ??? URL ??? ???? (?????, ???? ??) - Optional non-empty ASCII string. only characters in the range U+0021 to U+007E WebSocket - http://zany.kr (@ohmyzany) 7
  • 8. WebSocket Interface Websocket ?? ?? - websocket() ???? ????... URL ????? host, port, resource name, secure ? ?? ???? ??, SYNTAX_ERR exception ? throw ?? ??. ????? 80 ?? ??, 443 ??? ?? ??? ??. ??? ?? ?? ?? SECURITY_ERR exception throw. protocol ? ????? ?? ????, SYNTAX_ERR exception ? throw ?? ??. websocket ??? ?? (??? ???? readyState ??? CONNECTING ??? ????) ??? ??? ?? ?? (host, port, resource name, secure, protocol) WebSocket - http://zany.kr (@ohmyzany) 8
  • 9. WebSocket Interface readyState Attribute CONNECTING (0) : Connection ? ?? Established ?? ?? ??. OPEN (1) : ? ??? Established ? ??, ?? ??. CLOSING (2) : ??? ???? ?? ?. CLOSED (3) : ??? ??? ???. WebSocket - http://zany.kr (@ohmyzany) 9
  • 10. WebSocket Interface send(DOMString data) method ???? ??. readyState ? CONNECTING ? ??, INVALID_STATE_ERR exception. data ??? ??? ?? ?? ??, SYNTAX_ERR exception. WebSocket - http://zany.kr (@ohmyzany) 10
  • 11. WebSocket Interface close() method readySate ???? CLOSING, CLOSED ? ??, do nothing. ??? Established ? ?? ??, readyState ?? CLOSING ?? ??. ?? ?? ??? ?? ???? ?? ??, readyState ???? CLOSING ?? ??. ??? ??, readyState ???? CLOSING ?? ??. WebSocket - http://zany.kr (@ohmyzany) 11
  • 12. ? ?? ??? ?? phpwebsockets http://code.google.com/p/phpwebsockets/ jWebSocket ( java) http://jwebsocket.org/ web-socket-ruby (ruby) http://github.com/gimite/web-socket-ruby Socket-IO-node (node.js) http://github.com/LearnBoost/Socket.IO-node WebSocket - http://zany.kr (@ohmyzany) 12
  • 13. jWebSocket jWebSocket ?? ??? ???? ??? ??(bidirectional communication)? ?? ? ? ???. HTML5 ??? ????, ?????? ?????? ?? ??. Java/JavaScript ?? ??. ??? XHR(Xml Http Request)? Comet ???? ??. WebSocket - http://zany.kr (@ohmyzany) 13
  • 14. jWebSocket jWebSocket ?? jWebSocket Server (pure Java Based) server-to-client (S2C) streaming solutions server controlled (C2C) client-to-client-communication. jWebSocket Client (pure JavaScript Based) multiple subprotocols an optional user, session and timeout-management. No plug-ins required jWebSocket FlashBridge a Flash based WebSocket Wrapper (requires Flash plug-in) WebSocket - http://zany.kr (@ohmyzany) 14
  • 15. jWebSocket Infrastructure - Server WebSocket - http://zany.kr (@ohmyzany) 15
  • 16. jWebSocket Infrastructure - Client WebSocket - http://zany.kr (@ohmyzany) 16
  • 17. jWebSocket ?? ???? Browser Version Comment 6.0.x ? Chrome includes native WebSockets since 4.0.249. Chrome 5.0.x 4.0.249+ ? Tested and verified by jWebSocket team 2010-02-28. ? Safari 5.x includes native WebSockets 5.x Safari - tested and verified by jWebSocket team 2010-06-08. 4.x ? Safari 4.x does not yet provide the WebSocket class. 4.0b1 ? Firefox 3.7a6 and 4.0b1 now include native WebSockets Firefox 3.7a6 - tested and verified by jWebSocket team 2010-07-14 3.0+ ? including new Security features (Sec-WebSocket-Key header processing) Opera with 9+ ? Tested and verified by jWebSocket team 2010-03-28. FlashBridge 10+ WebSocket - http://zany.kr (@ohmyzany) 17
  • 18. jWebSocket ?? ?? ?? ?? ?? ????. Windows, Linux, Unix ?? ??. Prerequisites on the Server Java Runtime Environment (JRE) 1.5 JAVA_HOME ?? ?? : Java Home Directory. JWEBSOCKET_HOME ?? ?? : jWebSocket Home Directory. Windows ????? java.exe ? PATH ? ???? ?? ?? ??. WebSocket - http://zany.kr (@ohmyzany) 18
  • 19. jWebSocket ?? ?? ?? ?? ?? ???? - jWebSocketServer-0.9.5.zip ??? ????? ?? ?? Symbolic Link - /usr/local/jWebSocketServer JWEBSOCKET_HOME ?? ?? ?? - .bashrc or .bash_profile [root@zanyui-Mac-ProjWebSocket]#cpjWebSocketServer-0.9.5.zip/usr/local [root@zanyui-Mac-ProjWebSocket]#cd/usr/local [root@zanyui-Mac-ProjWebSocket]#unzipjWebSocketServer-0.9.5.zip [root@zanyui-Mac-ProjWebSocket]#ln-s/usr/local/jWebSocket-0.9.5/jWebSocketServer WebSocket - http://zany.kr (@ohmyzany) 19
  • 20. jWebSocket ?? ?? ?? 2?? ?? ? ?? ??. apache ? ??? ???? ??? ??. $ apachectl start java-jar$JWEBSOCKET_HOME/libs/jWebSocketServer-0.9.5.jar java-jar$JWEBSOCKET_HOME/libs/jWebSocketServer-0.9.5.jarlogtarget=consoleloglevel=info WebSocket - http://zany.kr (@ohmyzany) 20
  • 21. jWebSocket ????? ?? ????? ?? ?? ???? - jWebSocketClient-0.9.5.zip ??? ????? ?? ??? ?, apache ? ???? ?? ???? ? ?????, ~/Sites/jWebSocketClient ? ?? ????? ?? ? ??? http://localhost/~user/jWebSocketClient ? ????. Apache Web Server 2.2.14 ??, ?? ???? ???? ?? $vi/etc/apache2/httpd.conf IfModulealias_module/IfModule?????????? #ZanyAdd Alias/jWebSocket/Volumes/MacData/Projects/websocket/jWebSocket Directory/Volumes/MacData/Projects/websocket/jWebSocket OptionsIndexesFollowSymLinksMultiViewsExecCGI AllowOverrideNone Orderallow,deny Allowfromall /Directory WebSocket - http://zany.kr (@ohmyzany) 21
  • 22. ?? ? ?? ?? WebSocket Interface. jWebSocket. WebSocket - http://zany.kr (@ohmyzany) 22