Created
November 14, 2014 11:59
-
-
Save FrankGrimm/bbe83120abecb207a014 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 net = require('net'), | |
util = require('util'), | |
EventEmitter = require('events').EventEmitter; | |
var ServerConnection = function() { | |
var socket, | |
receivedData = ''; | |
var connect = function connect(hostAddress, port) { | |
socket = net.connect({ | |
host: "127.0.0.1", | |
port: 1234 | |
}); | |
socket.on('connect', function() { | |
console.log('Connected to: ' + hostAddress + ':' + port); | |
external.emit('test'); | |
}); | |
}; | |
var disconnect = function disconnect() { | |
if (isConnected) { | |
socket.end(); | |
} | |
}; | |
console.log(external); | |
var ExternalInterface = function() { | |
EventEmitter.call(this); | |
this.connect = connect; | |
this.disconnect = disconnect; | |
}; | |
util.inherits(ExternalInterface, EventEmitter); | |
var external = new ExternalInterface(); | |
return external; | |
}; | |
module.exports = ServerConnection; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment