Skip to content

Instantly share code, notes, and snippets.

@Valid
Created September 15, 2010 03:10
Show Gist options
  • Select an option

  • Save Valid/580181 to your computer and use it in GitHub Desktop.

Select an option

Save Valid/580181 to your computer and use it in GitHub Desktop.
var sys = require('sys'),
http = require('http'),
count = 0;
handshakeSite = http.createClient(80, 'ws30.sync.skoreit.com');
handshakeRequest = handshakeSite.request('POST', '/request.ashx?key=11111111-1111-1111-1111-111111111111&token=1284514994201', {
'host': 'ws30.sync.skoreit.com',
'Content-type': 'text/json; charset=utf-8'
});
handshakeJSON = [{
"channel": "/meta/handshake",
"id": count++,
"supportedConnectionTypes": ["long-polling", "callback-polling"],
"version": "1.0"
}];
handshakeRequest.end(JSON.stringify(handshakeJSON));
handshakeRequest.on('response', function (response) {
console.log('STATUS: ' + response.statusCode);
console.log('HEADERS: ' + JSON.stringify(response.headers));
response.setEncoding('utf8');
data = '';
response.on('data', function (chunk) {
data += chunk;
console.log('BODY: ' + chunk);
});
response.on('end', function () {
handshake = JSON.parse(data);
console.log(handshake[0].clientId);
connectSite = http.createClient(80, 'ws30.sync.skoreit.com');
console.log('1');
connectRequest = connectSite.request('POST', '/request.ashx?key=11111111-1111-1111-1111-111111111111&token=1284514994201', {
'host': 'ws30.sync.skoreit.com',
'Content-type': 'text/json; charset=utf-8',
'Connection': 'keep-alive'
});
console.log('2');
connectJSON = [{
"channel": "/meta/connect",
"connectionType": "long-polling",
"id": count++,
"clientId": handshake[0].clientId
}];
console.log(connectJSON);
connectRequest.end(JSON.stringify(connectJSON));
console.log('4');
connectRequest.on('response', function (response) {
console.log('STATUS: ' + response.statusCode);
console.log('HEADERS: ' + JSON.stringify(response.headers));
response.setEncoding('utf8');
data = '';
response.on('data', function (chunk) {
data += chunk;
console.log('BODY: ' + chunk);
});
response.on('end', function () {
connect = JSON.parse(data);
console.log(connect);
})
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment