Last active
August 29, 2015 14:17
-
-
Save masayuki5160/2eefc6be0550888fb19d to your computer and use it in GitHub Desktop.
EC2でnode.js, socket.ioのテスト
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var app = require('http').createServer(handler), | |
| io = require('socket.io').listen(app), | |
| fs = require('fs'); | |
| app.listen(3000); | |
| io.set('log level', 1); | |
| function handler(req, res) { | |
| fs.readFile(__dirname + '/index.html', function(err, data) { | |
| if (err) { | |
| res.writeHead(500); | |
| return res.end('Error'); | |
| } | |
| res.writeHead(200); | |
| res.write(data); | |
| res.end(); | |
| }) | |
| } | |
| io.sockets.on('connection', function(socket) { | |
| socket.on('emit_from_client', function(data) { | |
| socket.join(data.room); | |
| socket.emit('emit_from_server', 'you are in ' + data.room); | |
| socket.broadcast.to(data.room).emit('emit_from_server', data.msg); | |
| }); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 作業ログ | |
| $ sudo yum update -y | |
| $ sudo yum install git | |
| $ git clone https://github.com/creationix/nvm.git ~/.nvm | |
| $ source ~/.nvm/nvm.sh | |
| $ nvm ls-remote | |
| $ nvm install v0.12.1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //httpモジュールをインポート | |
| var http = require('http'); | |
| //Webサーバーの設定 | |
| http.createServer(function (req, res) { | |
| res.writeHead(200, {'Content-Type': 'text/plain'}); | |
| res.end('Hello World\n'); | |
| }).listen(3000); | |
| console.log('Server running. '); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| node.js起動時エラー : Error: listen EADDRINUSE | |
| http://qiita.com/kkam0907/items/65ceedbf3c71ae086838 | |
| [ec2-user@ip-172-16-0-55 ~]$ ps aux | grep node | |
| ec2-user 5725 0.0 2.0 760544 21144 pts/0 Tl 01:32 0:00 node app.js | |
| ec2-user 5761 0.0 0.0 114620 916 pts/0 S+ 01:43 0:00 grep node | |
| [ec2-user@ip-172-16-0-55 ~]$ sudo kill -9 5725 | |
| [1]+ 強制終了 node app.js | |
| [ec2-user@ip-172-16-0-55 ~]$ | |
| [ec2-user@ip-172-16-0-55 ~]$ | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ npm install socket.io | |
| > [email protected] install /home/ec2-user/node_modules/socket.io/node_modules/engine.io/node_modules/ws | |
| > (node-gyp rebuild 2> builderror.log) || (exit 0) | |
| make: ディレクトリ `/home/ec2-user/node_modules/socket.io/node_modules/engine.io/node_modules/ws/build' に入ります | |
| CXX(target) Release/obj.target/bufferutil/src/bufferutil.o | |
| make: ディレクトリ `/home/ec2-user/node_modules/socket.io/node_modules/engine.io/node_modules/ws/build' から出ます | |
| > [email protected] install /home/ec2-user/node_modules/socket.io/node_modules/socket.io-client/node_modules/engine.io-client/node_modules/ws | |
| > (node-gyp rebuild 2> builderror.log) || (exit 0) | |
| make: ディレクトリ `/home/ec2-user/node_modules/socket.io/node_modules/socket.io-client/node_modules/engine.io-client/node_modules/ws/build' に入ります | |
| CXX(target) Release/obj.target/bufferutil/src/bufferutil.o | |
| make: ディレクトリ `/home/ec2-user/node_modules/socket.io/node_modules/socket.io-client/node_modules/engine.io-client/node_modules/ws/build' から出ます | |
| [email protected] node_modules/socket.io | |
| ├── [email protected] ([email protected]) | |
| ├── [email protected] ([email protected]) | |
| ├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected]) | |
| ├── [email protected] ([email protected], [email protected], [email protected]) | |
| ├── [email protected] ([email protected], [email protected], [email protected], [email protected]) | |
| └── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
参考1: http://d.hatena.ne.jp/TROUBLE_MAKER/20141020/1413743196
参考2: http://www.atmarkit.co.jp/ait/articles/1501/09/news040.html