Skip to content

Instantly share code, notes, and snippets.

@geta6
Created March 19, 2013 06:28
Show Gist options
  • Save geta6/5194096 to your computer and use it in GitHub Desktop.
Save geta6/5194096 to your computer and use it in GitHub Desktop.
socket.ioのpingテスト用
fs = require 'fs'
path = require 'path'
app = require('http').createServer (req, res) ->
res.writeHead 200, 'Content-Type': 'text/html'
res.end fs.readFileSync (path.resolve 'public', 'index.html'), 'utf-8'
app.listen 3000
require('socket.io').listen(app).on 'connection', (socket) ->
socket.emit 'ping'
socket.on 'pong', console.log
<script src="/socket.io/socket.io.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
$(function () {
if(!io) {
window.alert('socket.io.jsが読めてない');
} else {
var socket = io.connect('http://test.geta6.net');
socket.on('ping', function(data) {
window.alert('pingキタ━━━━(゚∀゚)━━━━!!');
socket.emit('pong', 'キタ━━━━(゚∀゚)━━━━!!');
});
}
});
</script>
<h1>socket.ioのてすとだよ</h1>
{
"dependencies": {
"coffee-script": "1.4.0",
"socket.io": "*"
}
}
path = require('path');
require('coffee-script');
require(path.resolve('app'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment