Node.js Cluster+Socket.IO+Redisã«ãããªã¢ã«ã¿ã¤ã éç¥ã·ã¹ãã | ãµã¤ãã¼ã¨ã¼ã¸ã§ã³ã å ¬å¼ã¨ã³ã¸ãã¢ããã°
Node.js Cluster+Socket.IO+Redisã«ãããªã¢ã«ã¿ã¤ã éç¥ã·ã¹ãã | ãµã¤ãã¼ã¨ã¼ã¸ã§ã³ã å ¬å¼ã¨ã³ã¸ãã¢ããã°
WebSocket API(æ¥æ¬èªè¨³)ã¯ãå ¨äºéã®åæ¹åéä¿¡ãå¯è½ã«ããAPIã§ãããã«ãããªã¢ã«ã¿ã¤ã ãªWebã¢ããªã±ã¼ã·ã§ã³ãå®ç¾ãããã¨ãã§ããããã«ãªãã¾ããWebSocketã®ãããã³ã«å´ã®ä»æ§ãåå¹´ã»ã©åã«RFCã¨ãã¦çå®ãããããããè½ã¡ã¤ããã¨ããã§ãã(ã¾ã ä»æ§å¤æ´ãããå¯è½æ§ããªãã¨ã¯è¨ãåããªããã©) â»ãªãããã©ã¦ã¶ã¼ã¯ç¾æç¹(2012/07/26)ã§ã®åææ°ã®ãã©ã¦ã¶ã¼ã対象ã¨ãã¾ãã(Chrome20,Firefox14,Opera12,Safari5+Safari6) ã¾ãããã©ã¦ã¶ã¼ã«å®è£ ããã¦ããWebSocket(API)ã®ãã¨ã"WebSocketã¯ã©ã¤ã¢ã³ã"ã¨å¼ã¶ãã¨ã«ãã¾ãã WebSocketã¯ã©ã¤ã¢ã³ããå®è£ ããã¦ãããã©ã¦ã¶ã¼ 主è¦ãªãã©ã¦ã¶ã¼ã®ãã¡ç¾å¨ã«ããã¦WebSocketã¯ã©ã¤ã¢ã³ããå®è£ ãã¦ããã®ã¯Chrome,Firefox,O
次ä¸ä»£ã®Webã¢ããªã±ã¼ã·ã§ã³ã®ä¸æ ¸ãæ ãæè¡ã¨ãã¦ãHTML5ãã«æ³¨ç®ãéã¾ã£ã¦ããããããã¨ä¸¦ãã§æå¾ ããã¦ããæè¡ã«ãWebSocketããããã IETFã¨W3Cã«ãã£ã¦ä»æ§ã®çå®ãé²ãããã¦ãããæåã®ææ¡ä»¥æ¥å¹¾åº¦ãã®æ¹è¨ãçµã¦ã2011å¹´12æ11æ¥ã«ãã®ãããã³ã«ä»æ§ãRFCã®Proposed Standardï¼RFC 6455ï¼ã¨ãªã£ãã AjaxããCometãããã¦WebSocket㸠WebSocketã¯ã¦ã§ããµã¼ãã¨ãã©ã¦ã¶ãç´æ¥ã³ãã¯ã·ã§ã³ãå¼µã£ã¦åæ¹åéä¿¡ããããã®æè¡è¦æ ¼ã§ãããHTTPã¨ã¯ç°ãªãç¬èªã®è»½éãããã³ã«ã«ãã£ã¦éä¿¡ãè¡ãããããªã¼ãã¼ããããå°ãããé·æéã«æ¸¡ã£ã¦éä¿¡ããå ´åã§ãHTTPã³ãã¯ã·ã§ã³ãå æããå¿ è¦ããªãã¨ããã¡ãªãããããã WebSocketãçã¾ããèæ¯ã«ã¯ããµã¼ãã¨ãã©ã¦ã¶ããã£ã¨ãªã¢ã«ã¿ã¤ã ã«éä¿¡ãã¦æ å ±ã®é ä¿¡ãæ´æ°ãè¡ã
ä¸é¨ãç´è¨³ã§ã¯ãªãæ訳ããé¨åããããã¾ããåæã¨è¡¨ç¾ãç°ãªããã¨ããããã¾ãã®ã§ããäºæ¿ãã ããããã®æ¥æ¬èªè¨³ã¯ãç§ãç解ãæ·±ããããã«ãèªåãªãã«æ¥æ¬èªåãããã®ã§ããæ¬æ¥æ¬èªè¨³ã«ã¯ã翻訳ä¸ã®èª¤ããããå¯è½æ§ãããã¾ãããããã£ã¦ãå 容ã«ã¤ãã¦ä¸åä¿è¨¼ããããã®ã§ã¯ããã¾ãããæ£ç¢ºããæ±ããå ´åã«ã¯ãå¿ ãåæãåç §ãã¦ãã ãããå½æ¹ã¯ããã®ææ¸ã«ãã£ã¦å©ç¨è ã被ããããªãæ害ã®è²¬ä»»ãè² ãã¾ããããã誤ããªã©ãè¦ã¤ããããå½ãµã¤ãã®ãåãåããããé£çµ¡ããã ããã°å¹¸ãã§ãã åé¡ï¼The WebSocket API W3C Working Draft 29 September 2011 åæï¼http://www.w3.org/TR/2011/WD-websockets-20110929/ 翻訳æ¥ï¼2011/10/06 æçµæ´æ°æ¥ï¼2011/10/06 æ¦è¦ WebSocket ã¯ãJa
WebSocketï¼ã¦ã§ãã½ã±ããï¼ã¯ãåä¸ã®TCPã³ãã¯ã·ã§ã³ä¸ã«åæ¹åéä¿¡ã®ãã£ã³ãã«ãæä¾ãããã³ã³ãã¥ã¼ã¿ã®éä¿¡ãããã³ã«ã®1ã¤ã§ãããWebSocketãããã³ã«ã¯ã2011å¹´ã«RFC 6455ã¨ãã¦IETFã«ããæ¨æºåããããWeb IDLï¼è±èªçï¼ä¸ã®WebSocket APIã¯ãå½åW3Cã«ããæ¨æºãããå¾ã«WHATWGã«å¼ãç¶ããã¦ããã WebSocketã¯HTTPã¨ã¯ç°ãªããããã³ã«ã§ãããã¨ãã«OSIåç §ã¢ãã«ã®ã¬ã¤ã¤ã¼7ã«ä½ç½®ããã¬ã¤ã¤ã¼4ã®TCPã«ä¾åãã¦ããã両è ã¯ç°ãªããããã³ã«ã§ããããRFC 6455ã§ã¯ãWebSocketã¯ãHTTPãããã·ã¨ä»²ä»è ããµãã¼ãããããã«ãHTTPã®443çªããã³80çªãã¼ãä¸ã§åä½ããããã«è¨è¨ããã¦ãããã¨è¿°ã¹ããã¦ããããã«ãHTTPãããã³ã«ã¨äºææ§ããããäºææ§ãå®ç¾ããããã«ãWebSocketã®ãã³ãã·ã§ã¤
ãã®ã¦ã§ããµã¤ãã¯è²©å£²ç¨ã§ãï¼ twiwt.org ã¯ãããªãããæ¢ãã®æ å ±ã®å ¨ã¦ã®ææ°ãã¤æé©ãªã½ã¼ã¹ã§ããä¸è¬ãããã¯ããããããæ¤ç´¢ã§ããå 容ã¯ãtwiwt.orgãå ¨ã¦ã¨ãªãã¾ããããªãããæ¢ãã®å 容ãè¦ã¤ãããã¨ãé¡ã£ã¦ãã¾ãï¼
Expressã¯éåã¨ãã¦æ±ããã³ãã¬ã¼ãã¨ã³ã¸ã³ãé¸æã§ãã¾ããããã©ã«ãã®ãã³ãã¬ã¼ãã¨ã³ã¸ã³ã¯ãjadeãã§ããjadeã¯ä»¥ä¸ã®ããã«ãã¦ã¤ã³ã¹ãã¼ã«ãã¾ãã $ npm install jade jadeã¯XMLå½¢å¼ã§ãªããã¤ã³ãã³ãå½¢å¼ã§è¨è¿°ãã¾ããjade以å¤ã«ããEJSãCoffeeKupãHamlãªã©ã®ãã³ãã¬ã¼ããããã¾ãã®ã§ã好ã¿ã§é¸ã³ã¾ããããHTMLå½¢å¼ã§æ¸ãããå ´åã¯EJSãé¸æããã¨ããã§ãããã Expressã¨jadeãã¤ã³ã¹ãã¼ã«ããããå®éã«Webã¢ããªã®éå½¢ãä½ã£ã¦ã¿ã¾ãããã $express sample create : sample create : sample/app.js create : sample/logs create : sample/pids create : sample/public/images create : sam
2024å¹´ä¸åæã®ãã£ã«ã åçãã¡ ãµã¨æ°ãã¤ãã¨2024å¹´ãæ®ãå ãã ããã¦ãµã¨æ¯ãè¿ãã¨ãã®ããã°ã«æ²è¼ããåçãGRIIIã§æ®ã£ããã®ã°ããã«ãªã£ã¦ããã®ã ãã©ã決ãã¦ãã£ã«ã ã«é£½ããã¨ãããã¨ã§ã¯ãªãããã£ã«ã ã¯ãã£ã«ã ã§æ·¡ã ã¨æ®ãç¶ãã¦ããããã¢ãã¯ããã«ã©ã¼ãã¬ããã¤ãéãèªå® ã§â¦
WebSocket Communication èªå·±ç´¹ä» ãã¿ãã (Twitter@kamiyam) ã·ã¹ãã éçºä¼ç¤¾ ã»ã¨ãã©Webã®ã·ã¹ãã Javaã»C#ãã¡ã¤ã³ã®ããã°ã©ã å èªåè»æ´å士ã§ã ä»æ¥ã¯å¤§éªããæ¥ã¾ãã ã¢ã¸ã§ã³ã WebSocketã¨ã¯ï¼ ç¾ç¶WebSocketã§ä½ãã§ããã®ãï¼ ç§ã®ã»ãã·ã§ã³ã§ã¯é£ãã話ã¯æãã«ãã¦WebSocketã使ã£ããã¢ãä¸å¿ã«ãéããããã¨æãã¾ãã ã¨ãäºåè³æå ¬éæã¯èãã¦ãã¾ãããããã¢ã ãã§30åãããªãã®ã§Webãã¼ã¹ã®å®è£ ã«ã¤ãã¦ã®è§£èª¬ãªã©ã WebSocketã¨ã¯ï¼ ä»æ¥ãä½åº¦ãåºã¦ããã¨æãã¾ããããªã¢ã«ã¿ã¤ã ã«åæ¹åéä¿¡ãå¯è½ã«ãããããã³ã«ã§ãã SyncSlide WebSocket Communication http://prog.re-d.net/demo/slide/20110528/ USTREAMãã
åå²ãå¯è½ãªéãå¦çããµã¼ãã¼å´ã§å®è¡ãã¦ãå¦çã®ç¶æ³ã®å¤åãã¯ã©ã¤ã¢ã³ãå´ã§è¡¨ç¤ºããããã¨ãï¼ããã°ã¬ã¹ãã¼ã¿ãããªã®ãä½ãã¨ãï¼ãã©ãããæ¹æ³ããããã¡ãã£ã¨èãã¦ã¿ããåé¡ã¯ãã©ããã£ã¦å¦çã®é²æ©ç¶æ³ã®æ å ±ãã¯ã©ã¤ã¢ã³ããµã¤ãã§ãªã¢ã«ã¿ã¤ã ã«åãåãããã¨ãããã¨ã ã¾ãæåã«æµ®ãã¶ã®ããåå²ãããã¿ã¹ã¯ãï¼ã¤è¡ãAPIããµã¼ãã¼å´ã§ç¨æãã¦ãã¯ã©ã¤ã¢ã³ãå´ããJSã®setTimeoutãªãã©ã¤ãã©ãªã®deferredãªã使ã£ã¦ä¸¦è¡ãªã¯ã¨ã¹ããã¦ãã³ã¼ã«ããã¯ã§ããã°ã¬ã¹ãã¼ãæ¸ãæããã»ã»ã»ã¿ãããªã®ãæµ®ããã ãããã©ãPerlã«ã¯CoroãAE::HTTPã¿ãããªä¾¿å©ãªãã®ããããããæè§ãªã®ã§ä¸¦è¡å¦çã®å¶å¾¡ã¯ããã¾ã§ãµã¼ãã¼å´ã§ã§ããªããï¼ãã¨èãã¦ããã ã§ã次ã«æãä»ããã®ãããåå²ãããã¿ã¹ã¯ãï¼ã¤çµãããã³ã«ãµã¼ãã¼å´ããã¯ã©ã¤ã¢ã³ãå´ã«æ å ±ãpushããããã¨ãããã
ã¯ããã« æ¯å¹´ãµã¼ãã¼ãµã¤ãJavaScriptãæµè¡ãã¨è¨ã£ã¦ãã¿ãªããããã«ã¡ã¯ããã¼ã§ãã ã¨ãããã¨ã§ãnode.jsãã¯ããã¦ã¿ã¾ããã Twitter Streaming APIã§åå¾ãããã¼ã¿ã¼ãWebSocket㧠æ¥ç¶ããã¯ã©ã¤ã¢ã³ãã«åºåãããã¢ãä½æããã®ã§ç´¹ä»ãããã¨æãã¾ãã ä»åã®ãã¢ã«ã¤ã㦠ä»åä½æãããã¢ã¯ node.jsã®HttpClinetã§Twtter Streaming APIã§Twtterãããã¼ã¿ãåå¾ãã¦ã node.jsã®WebSocket Serverã§ãã®ãã¼ã¿ãæ¥ç¶ãã¦ããWebSocket対å¿ãã©ã¦ã¶ã«éä¿¡ããã¨ãããã¨ã ãã£ã¦ãã¾ãã Twitter Streaming APIã§åå¾ã§ããããã«ããã åããã®ã«http-basic-authãå¿ è¦ã§ãã npm install http-basic-auth streaming
id:Jxck(@Jxck_)ããããã®ãªã¯ã¨ã¹ããããã¾ããã®ã§ãç¾ç¶ã§ã®WebSocketæ å ±ãã¾ã¨ãã¦ããã¾ãã â»ãã®æ å ±ã¯2010/9/1æç¹ã®ãã®ã§ããã覧ã«ãªã£ã¦ããæç¹ã®æ å ±ã¨ã¯å¤ãã£ã¦ããå¯è½æ§ãããã¾ãã â»2010/9/1:ããããæ´æ°ãã¾ããã â»æ¸ããã¦ããç¸å½ãªæ¥æ°ããã£ã¦ãã¾ãã®ã§ããã®ã¨ã³ããªã¼ã¯å½¹ã«ç«ã¡ã¾ãããWebSocketã¯RFC(http://www.ietf.org/rfc/rfc6455.txt)ãã§ã¾ãããææ°ã®ç¶æ³ã¯ä»ã®ãµã¤ããã覧ã«ãªããã¨ããå§ããã¾ããæ å ±ãã¢ãããã¼ãã§ããªãã¦ãã¿ã¾ããã ãã£ãã説æ ä¸è¨ã§èª¬æããã¨ãWebServerã¨WebBrowserç¨ã®åæ¹åéä¿¡ç¨ã®ãããã³ã«ã Serverå´ããã®ããã·ã¥ãã§ããã®ã§ãXHRã§ãã¼ãªã³ã°ããå¿ è¦ããªãã ç¾è¡ã®WebSocket対å¿ãã©ã¦ã¶å´ã«ã¯ï¼same origi
é害
ã©ã³ãã³ã°
ã©ã³ãã³ã°
ãªãªã¼ã¹ãé害æ å ±ãªã©ã®ãµã¼ãã¹ã®ãç¥ãã
ææ°ã®äººæ°ã¨ã³ããªã¼ã®é ä¿¡
å¦çãå®è¡ä¸ã§ã
j次ã®ããã¯ãã¼ã¯
kåã®ããã¯ãã¼ã¯
lãã¨ã§èªã
eã³ã¡ã³ãä¸è¦§ãéã
oãã¼ã¸ãéã
{{#tags}}- {{label}}
{{/tags}}