Last active
March 25, 2017 15:18
-
-
Save Anderson-Juhasc/faa86eaacaf53803ec8722845c0d15fd to your computer and use it in GitHub Desktop.
Socket.io bitcoin address
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
<!DOCTYPE HTML> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title></title> | |
</head> | |
<body> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/1.7.3/socket.io.min.js"></script> | |
<script type="text/javascript"> | |
var socket = io('ws://localhost:8000', { | |
}); | |
socket.on('connect', function() { | |
console.log("connected!"); | |
socket.emit('address', { address: '198aMn6ZYAczwrE5NvNTUMyJ5qkfy4g3Hi' }); | |
socket.on('message', function (data) { | |
var data = JSON.parse(data); | |
console.log(data.data); | |
}); | |
socket.on('disconnect', function() { | |
console.log("disconnect!"); | |
}); | |
}); | |
</script> | |
</body> | |
</html> |
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() | |
var io = require('socket.io')(app); | |
var request = require('request'); | |
app.listen(8000); | |
var clients = 0; | |
var address = ''; | |
io.on('connection', function (socket) { | |
socket.on('message', function (msg) { | |
console.log(msg); | |
socket.emit(msg); // Send message to sender | |
}); | |
socket.on('address', function (data) { | |
address = data.address; | |
}); | |
socket.on('disconnect', function () { | |
}); | |
}); | |
// emulate one broadcast message per second | |
setInterval(function() { | |
request.get('http://btc.blockr.io/api/v1/address/info/' + address, function(err,httpResponse,body){ | |
httpResponse = JSON.parse(httpResponse.body); | |
httpResponse = JSON.stringify(httpResponse); | |
io.emit("message", httpResponse); | |
}) | |
}, 5000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment