forked from SeanTRobinson/Angular_Mongo_Node-Tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Sean Robinson
authored and
Sean Robinson
committed
Aug 7, 2014
1 parent
1bfe6ae
commit 65cf079
Showing
2 changed files
with
45 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
var net = require('net'); | ||
function getConnection(connName){ | ||
var client = net.connect({port: 8107, host:'localhost'}, function() { | ||
console.log(connName + ' Connected: '); | ||
console.log(' local = %s:%s', this.localAddress, this.localPort); | ||
console.log(' remote = %s:%s', this.remoteAddress, this.remotePort); | ||
this.setTimeout(500); | ||
this.setEncoding('utf8'); | ||
this.on('data', function(data) { | ||
console.log(connName + " From Server: " + data.toString()); | ||
this.end(); | ||
}); | ||
this.on('end', function() { | ||
console.log(connName + ' Client disconnected'); | ||
}); | ||
this.on('error', function(err) { | ||
console.log('Socket Error: ', JSON.stringify(err)); | ||
}); | ||
this.on('timeout', function() { | ||
console.log('Socket Timed Out'); | ||
}); | ||
this.on('close', function() { | ||
console.log('Socket Closed'); | ||
}); | ||
}); | ||
return client; | ||
} | ||
function writeData(socket, data){ | ||
var success = !socket.write(data); | ||
if (!success){ | ||
(function(socket, data){ | ||
socket.once('drain', function(){ | ||
writeData(socket, data); | ||
}); | ||
})(socket, data); | ||
} | ||
} | ||
var Dwarves = getConnection("Dwarves"); | ||
var Elves = getConnection("Elves"); | ||
var Hobbits = getConnection("Hobbits"); | ||
writeData(Dwarves, "More Axes"); | ||
writeData(Elves, "More Arrows"); | ||
writeData(Hobbits, "More Pipe Weed"); |