socket.ioã®websocketæ¥ç¶ãdisconnectedãconnectedãç¹°ãè¿ãã¦ãã¾ã
ã¨ãdisconnectedãconnectedãç¹°ãè¿ãã
21 Apr 01:29:34 - Initializing client with transport "websocket"
21 Apr 01:29:34 - Client 37915311800315976 connected
21 Apr 01:29:56 - Client 37915311800315976 disconnected
21 Apr 01:30:02 - Initializing client with transport "websocket"
21 Apr 01:30:02 - Client 12511056219227612 connected
21 Apr 01:30:23 - Client 12511056219227612 disconnected
21 Apr 01:30:30 - Initializing client with transport "websocket"
â¦
websocketã¯æ¥ç¶ãç¶æãããããã³ã«ãããªãã£ãã®ãã
ããããããè¦ãã¨
ãç´22ç§éæ¥ç¶ â åãã â ç´6ç§å¾åæ¥ç¶
ã¨æ±ºã¾ã£ããã¿ã¼ã³ã®ç¹°ãè¿ãã
ãªã«ãæªããã ããããããæ£å¸¸ãªã®ãããããããããªããwebsocketãã®ãã¼ã
ãµã¼ãå´ã®ã³ã¼ãï¼socket.ioçï¼
var http = require('http'), io = require('socket.io'); server = http.createServer(function(req, res){ console.log('[http] on connection ' + connect_count); res.writeHead(200, {'Content-Type': 'text/html'});_ res.end('<h1>Hello world</h1>');_ }); server.listen(8000); var socket = io.listen(server); socket.on('connection', function(client){ client.on('message', function(){ console.log('on message ');}) client.on('disconnect', function(){ console.log('on disconnect ');}) });
ã¯ã©ã¤ã¢ã³ãå´ï¼ãã©ã¦ã¶ï¼ã®ã³ã¼ã
ï¼ãã®HTMLã¨ä¸ã§ãã¼ãããJSã¯å¥ã§ç«ã¦ãApacheãè¿ãã¦ããï¼
<script src="http://motoki.local/socket-io/socket.io.js"></script> <script> var socket = new io.Socket('motoki.local',{port:8000}); socket.port = 8000; socket.connect(); socket.on('connect', function(){console.log('connect');}) socket.on('message', function(){console.log('message');}) socket.on('disconnect', function(){console.log('disconnect');}) </script>
ä»ã®ã³ã¼ãã§è©¦ãã¦ã¿ã
ãµã¼ãå´ããsocket.ioã§ãªãã§ã
ã¯ã©ã¤ã¢ã³ãå´ããsocket.io.jsã§ãªããã©ã¦ã¶ãã¤ãã£ãã®WebSocketã§è©¦ãã¦ã¿ãã
ã¯ã©ã¤ã¢ã³ãå´ï¼ãã©ã¦ã¶ã®ã³ã¼ãï¼
<html> <body> <script type="text/javascript"> var connect = function() { conn = new WebSocket("ws://motoki.local:8000/test"); }; window.onload = connect; </script> </body>
ãµã¼ãå´ï¼node-websocket-serverçï¼
var ws = require('./node-websocket-server/lib/ws/server'); var server = ws.createServer(); //var ws = require("websocket-server"); server.addListener("connection", function(connection){ connection.addListener("close", function(){ console.log('client close'); }); }); server.addListener("close", function(connection){ console.log('close'); }); server.listen(8000);
ãã¼ããã¡ããã¨æ¥ç¶åããªããåå ä¸æã
ããããã°NOD32ãã®HTTPãã§ãã¯ãããã¦ããã
ã§ããã®åã¯sendãéããªãã£ãã ãã®ã¯ãï¼ãã®æã¯socket.ioãããªãã£ããã©ï¼
http://d.hatena.ne.jp/motsat/20110411/1302530960
ä¸å¿ä»åãHTTPãã§ãã¯ã解é¤ã
ããã¦ãsocket.ioçã®ã³ã¼ãã試ãã
æ¥ç¶åããªããªã£ãã
ä¸æè°ãªãã¨ãèµ·ãã£ãããNOD32ãçããã¨ããã¯ãããããå¿ãã¦ãã¾ããã
NOD32ããã¯HTML5æªå¯¾å¿ã§ãHTTPã§ã®ã³ãã¯ã·ã§ã³å¼µã£ãã®ã«ãä¸ã§ã¯ããããª(WebSocket)ãªããã¨ããã¦ããããæã£ã¦ãããã ãããã
ãã©ã¦ã¶ã ãã§ç¡ããã¦ã¤ã«ã¹ãã§ãã¯ã½ãããHTML5対å¿ãã¦ã»ãããã®ã§ãã