Created
May 23, 2012 15:03
-
-
Save alexstrat/2775751 to your computer and use it in GitHub Desktop.
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
| var util = require('util'); | |
| var events = require('events'); | |
| var io = require('socket.io-client'); | |
| function Socket(type, listener, host, io_options) { | |
| events.EventEmitter.call(this); | |
| if (typeof listener === 'function') | |
| this.on('message', listener); | |
| //args swap | |
| if(typeof listener === 'string') { | |
| host = listener; | |
| io_options = host; | |
| } | |
| io_options = io_options || {}; | |
| //use sio manespaceing | |
| io_options.uri = '/simudp'; | |
| //connect socket | |
| this.sio = io.connect(host, io_options); | |
| } | |
| util.inherits(Socket, events.EventEmitter); | |
| exports.Socket = Socket; | |
| exports.createSocket = function(type, listener) { | |
| return new Socket(type, listener); | |
| }; | |
| Socket.prototype.bind = function(port, address) { | |
| var self = this; | |
| this.sio.on('listening', function(address) { | |
| self.address = address; | |
| self.emit('listening'); | |
| }) | |
| this.sio.emit('bind', {port : port, address : address}); | |
| }; | |
| Socket.prototype.send = function(buffer, | |
| offset, | |
| length, | |
| port, | |
| address, | |
| callback) { | |
| var self = this; | |
| if (offset >= buffer.length) | |
| throw new Error('Offset into buffer too large'); | |
| if (offset + length > buffer.length) | |
| throw new Error('Offset + length beyond buffer length'); | |
| callback = callback || noop; | |
| }; | |
| Socket.prototype.close = function() { | |
| this.emit('close'); | |
| }; | |
| Socket.prototype.address = function() { | |
| return address; | |
| }; | |
| Socket.prototype.setBroadcast = function(arg) { | |
| throw new Error('not implemented') | |
| }; | |
| Socket.prototype.setTTL = function(arg) { | |
| throw new Error('not implemented') | |
| }; | |
| Socket.prototype.setMulticastTTL = function(arg) { | |
| throw new Error('not implemented') | |
| }; | |
| Socket.prototype.setMulticastLoopback = function(arg) { | |
| throw new Error('not implemented') | |
| }; | |
| Socket.prototype.addMembership = function(multicastAddress, | |
| interfaceAddress) { | |
| throw new Error('not implemented') | |
| }; | |
| Socket.prototype.dropMembership = function(multicastAddress, | |
| interfaceAddress) { | |
| throw new Error('not implemented') | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment