Created
September 9, 2014 15:09
-
-
Save vird/881ae3552e0c9f93a32e to your computer and use it in GitHub Desktop.
seems primus+engine.io can't utf8
This file contains 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
4{"switch":"pongРУССÐÐÐ"} |
This file contains 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
<html ng-app="root"> | |
<head> | |
<title>Template socketio angular</title> | |
<script src="/primus/primus.js"></script> | |
<script> | |
var websocket = new Primus(location.origin); | |
websocket.on('data', function(data) { | |
console.log(data); | |
}); | |
setTimeout(function(){ | |
websocket.write({switch:"ping"}); | |
},5000); | |
</script> | |
</head> | |
<body> | |
<div> | |
</div> | |
</body> | |
</html> |
This file contains 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
process.on 'uncaughtException', (err) -> | |
console.log err | |
console.log err.stack | |
express = require 'express' | |
http = require 'http' | |
ect = require 'ect' | |
Primus = require 'primus' | |
body_parser = require 'body-parser' | |
compression = require 'compression' | |
# ################################################################################################### | |
ectRenderer = ect | |
root : 'views' | |
# ################################################################################################### | |
app = express() | |
app.use compression() | |
app.use body_parser.urlencoded extended: true | |
app.set 'view engine', 'ect' | |
app.engine 'ect', ectRenderer.render | |
app.get '/', (req, res, next)-> | |
res.render 'index.ect' | |
server = http.createServer(app).listen(1337) | |
primus = new Primus server, | |
transformer : 'engine.io' | |
# transformer : 'websockets' | |
parser : 'JSON' | |
primus.on 'connection', (socket)-> | |
socket.on 'data', (data)-> | |
switch data.switch | |
when "ping" | |
socket.write | |
'switch':'pongРУССКИЙ' | |
console.log "started" |
This file contains 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 express ext primus ws engine.io body-parser compression | |
mkdir views | |
mv index.ect views/index.ect |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment