Changeset View
Changeset View
Standalone View
Standalone View
support/aphlict/server/lib/AphlictListener.js
| var JX = require('javelin').JX; | var JX = require('javelin').JX; | ||||
| JX.install('AphlictListener', { | JX.install('AphlictListener', { | ||||
| construct : function(id, socket) { | construct: function(id, socket) { | ||||
| this._id = id; | this._id = id; | ||||
| this._socket = socket; | this._socket = socket; | ||||
| }, | }, | ||||
| members : { | members: { | ||||
| _id : null, | _id: null, | ||||
| _socket : null, | _socket: null, | ||||
| getID : function() { | getID: function() { | ||||
| return this._id; | return this._id; | ||||
| }, | }, | ||||
| getSocket : function() { | getSocket: function() { | ||||
| return this._socket; | return this._socket; | ||||
| }, | }, | ||||
| getDescription : function() { | getDescription: function() { | ||||
| return 'Listener/' + this.getID(); | return 'Listener/' + this.getID(); | ||||
| }, | }, | ||||
| writeMessage : function(message) { | writeMessage: function(message) { | ||||
| var serial = JSON.stringify(message); | var serial = JSON.stringify(message); | ||||
| var length = Buffer.byteLength(serial, 'utf8'); | var length = Buffer.byteLength(serial, 'utf8'); | ||||
| length = length.toString(); | length = length.toString(); | ||||
| while (length.length < 8) { | while (length.length < 8) { | ||||
| length = '0' + length; | length = '0' + length; | ||||
| } | } | ||||
| this._socket.write(length + serial); | this._socket.write(length + serial); | ||||
| } | } | ||||
| } | } | ||||
| }); | }); | ||||