Skip to content

Instantly share code, notes, and snippets.

@yorkie
Last active August 29, 2015 14:02
Show Gist options
  • Save yorkie/0cc4859376882a288a70 to your computer and use it in GitHub Desktop.
Save yorkie/0cc4859376882a288a70 to your computer and use it in GitHub Desktop.
JSON Stream Protocol Example
// client - side
var client = XMLStream('xmlstream.com', 3000);
client.on('data', function(stanza) {
// TODO
});
client.on('connect', function() {
// writeMessage
client.writeMessage({
type: 'auth',
user: 'yorkie',
token: 'beep\nboop'
});
// write message
client.writePresence();
});
client.connect();
// server - side
var app = XMLStream();
app.on('data', function(req, res) {
if (req.type == 'login') {
res.write({
type: 'success'
});
}
if (req.type == 'logout') {
res.end({
type: 'success'
});
}
});
app.on('message', function(msg) {
// TODO
});
app.on('presence', function(presence) {
// TODO
});
app.listen(3000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment