Last active
August 29, 2015 14:17
-
-
Save shouse/dfb4612a8d77a441fad8 to your computer and use it in GitHub Desktop.
Titanium WebSocket demo. Based on https://github.com/omorandi/tiws
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
function websocketSetup() { | |
//@TODO check config.json for socket setting | |
uri = 'ws://localhost:8765'; | |
tiws = require('net.iamyellow.tiws').createWS(); | |
tiws.addEventListener('open', function () { | |
alert('opened') | |
_self.info('Websocket opened'); | |
socketConnected = true; | |
websocketSendMessage("THIS IS A TEST MESSAGE FROM TITANIUM"); | |
}); | |
tiws.addEventListener('close', function (ev) { | |
Ti.API.info(ev); | |
socketConnected = false; | |
}); | |
tiws.addEventListener('error', function (ev) { | |
Ti.API.error(ev); | |
}); | |
tiws.addEventListener('message', function (ev) { | |
Ti.API.log(ev); | |
alert('WS Message: ' + JSON.stringify(ev, null, 4)); | |
}); | |
tiws.open(uri); | |
} | |
function websocketSendMessage(message) { | |
tiws.send(message); | |
} |
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
console.log('Starting WebSocketServer!'); | |
var WebSocketServer = require('ws').Server | |
, wss = new WebSocketServer({port: 8765}); | |
wss.on('connection', function(ws) { | |
console.log('CONNECTED TO WS!'); | |
ws.on('message', function(message) { | |
console.log('received: %s', message); | |
}); | |
ws.send('something'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment