-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.js
64 lines (47 loc) · 1.31 KB
/
client.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
var spdy = require('spdy');
var argo = require('argo');
var WebSocket = require('./web_socket');
var server = spdy.createServer({
connection: {
windowSize: 1024 * 1024, // Server's window size
autoSpdy31: false
},
spdy: {
plain: true,
ssl: false
}
});
var cloud = argo()
.use(function(handle) {
handle('request', function(env, next) {
if (env.request.url === '/push') {
var data = new Buffer(JSON.stringify({ timestamp: new Date().getTime() }));
var opts = {
request: { 'Host': 'fog.argo.cx',
'Content-Length': data.length,
"Adam": "Magaluk"
},
};
var stream = env.response.push('/event', opts);
stream.end(data);
}
next(env);
})
})
.target("http://localhost:1337");
cloud = cloud.build();
server.on('request', cloud.run);
// Setup ping event handler to passes event to
// sockets event emitter
server.on('ping', function(socket) {
socket.emit('spdyPing');
});
console.log('Connecting to ', process.argv[2])
var ws = new WebSocket(process.argv[2], {});
ws.on('open', function onOpen(socket) {
server.emit('connection', socket);
socket.on('spdyPing', function() {
console.log('got spdy ping');
});
});
ws.start();