Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added udp example

  • Loading branch information...
commit 6329f43d5a52da30d36e8e96e63577467c0d354b 1 parent f8737b5
Linux User authored
Showing with 81 additions and 0 deletions.
  1. +47 −0 couchdb-echo.js
  2. +9 −0 private.js
  3. +25 −0 udp-listener.js
47 couchdb-echo.js
View
@@ -0,0 +1,47 @@
+var keys = require('./private').couchdb(),
+ connect = require('connect'),
+ couch = require('couchdb'),
+ client = couch.createClient(keys.port, keys.domain, keys.user, keys.password),
+ db = client.db('syllabi');
+
+/*
+ * Create a database 'myDB'
+ * Create a view 'all'
+ * put all documents into that view with no key (no sorting)
+ * and with no descrimitation (all keys)
+ */
+var myDb = "exampledb"
+client.request('put', '/' + myDb);
+db.saveDesign(myDb, {
+ views: {
+ "all": {
+ map: function(doc) {
+ emit(null, doc);
+ }
+ }
+ }
+});
+
+
+var coolaj86 = {
+ name: "AJ ONeal",
+ email: "coolaj86@email.com",
+ phone: "777-555-2121"
+},
+mvndaai = {
+ name: "Jason Mavandi",
+ email: "mvndaai@email.com",
+};
+
+function log(err, data) {
+ console.log('err: ' + err);
+ console.log('data: ' + JSON.stringify(data));
+}
+
+db.saveDoc(coolaj86.email, coolaj86, log);
+db.saveDoc(mvndaai.email, mvndaai, log);
+
+db.getDoc(coolaj86.email, log);
+db.getDoc(mvndaai.email, log);
+
+db.view(myDb, 'all', {}, log);
9 private.js
View
@@ -6,4 +6,13 @@ module.exports = {
secret: 'ffffffffffffffffffffffffffffffff'
};
}
+ couchdb: function () {
+ throw Error('Change these keys before use');
+ return {
+ port: '80',
+ domain: 'YOUR_COUCH.couchone.com',
+ user: 'YOUR_USER',
+ password: 'YOUR_PASSWORD'
+ };
+ }
};
25 udp-listener.js
View
@@ -0,0 +1,25 @@
+(function () {
+ var dgram = require('dgram'),
+ server,
+ address = "0.0.0.0", // any available addresses
+ port = 25000, // change as you wish
+ protocol = "udp4";
+
+
+ server = dgram.createSocket(protocol);
+
+ server.on("message", function (msg, rinfo) {
+ console.log("server got: " + msg + " from " +
+ rinfo.address + ":" + rinfo.port);
+ });
+
+ server.on("listening", function () {
+ var address = server.address();
+ console.log("server listening " +
+ address.address + ":" + address.port);
+ });
+
+ server.bind(port, address);
+ // Expected Output: server listening 0.0.0.0:41234
+ // If you get "Error: EADDRINUSE, Address already in use", choose a different port number
+}());
Please sign in to comment.
Something went wrong with that request. Please try again.