Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Documentation & Rename

  • Loading branch information...
commit 1f44ed7a04ee3ac4a0702e43193682260beec9f6 1 parent a68b392
phidelta authored
View
2  API.markdown
@@ -11,7 +11,7 @@ This is the same as for the standard [Datagram Sockets](http://www.nodejs.org/ap
* joinGroup(<Multicast-IP as a String>)
* leaveGroup(<Multicast-IP as a String>)
-* setMulticastTTL(<TTL as an Integer between 0 and 255 (inclusive)>)
+* setMulticastTTL(<TTL as an Integer between 1 and 255 (inclusive)>)
* setMulticastInterface(<IP of a local non-looping interface as a String>)
createSocket()
View
7 CHANGELOG.markdown
@@ -1,4 +1,5 @@
-## Version 0.0.1
- * Basic functionality: joinGroup / leaveGroup
-
+NodeJS UDP-Multicast - Change-Log
+=================================
+## Version 0.0.1
+ * Basic functionality: joinGroup / leaveGroup / setMulticastTTL / setMulticastInterface
View
48 README.markdown
@@ -1,5 +1,5 @@
-NodeJS-UDP-Multicast
-=========================
+NodeJS UDP-Multicast
+====================
Multicast UDP Sockets for NodeJS
@@ -7,13 +7,49 @@ Multicast UDP Sockets for NodeJS
[Github repo]: http://github.com/phidelta/NodeJS-UDP-Multicast.git
[module site]: http://github.com/phidelta/NodeJS-UDP-Multicast
-
-Dependencies
+Installation
------------
+$ cd ~/.node_libraries
+$ git clone http://github.com/phidelta/NodeJS-UDP-Multicast.git mdgram
+$ cd mdgram
+$ node-waf configure build
+$ ln -s ./build/default/bindings.node bindings.node
+OR
-License
+$ git clone http://github.com/phidelta/NodeJS-UDP-Multicast.git mdgram
+$ cd mdgram
+$ npm install
+
+Synopsis
+--------
+
+Create a Listening Socket:
+
+ var mdgram=require('mdgram');
+ var socket=mdgram.createSocket('udp4');
+ socket.bind(1234);
+ socket.joinGroup("225.0.0.73");
+
+Setting the Multicast TimeToLive:
+
+ socket.setMulticastTTL(5);
+
+Setting the Multicast Interface:
+
+ socket.setMulticastInterface("192.168.0.3"); // Where 192.168.0.3 is the IP of the interface you want to use Multicast on
+ socket.setMulticastInterface(); // If you want the system to figure out which to use (commonly the first non-loopback interface)
+
+Leaving a Multicast Group:
+
+ socket.leaveGroup("225.0.0.73");
+
+
+Authors
-------
+Philipp Dunkel (phidelta at phideltacity.net)
-MIT license. See license text in file [LICENSE](http://github.com/Sannis/node-mysql-libmysqlclient/blob/master/LICENSE).
+License
+-------
+MIT license. See license text in file [LICENSE](http://github.com/phidelta/NodeJS-UDP-Multicast/LICENSE).
View
8 mdgram.cc
@@ -62,7 +62,7 @@ namespace node_multicast {
mreq.imr_interface.s_addr=htonl(INADDR_ANY);
if (setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) < 0) {
- return False();
+ return ThrowException(ErrnoException(errno, "socket"));
}
return True();
@@ -96,7 +96,7 @@ namespace node_multicast {
mreq.imr_interface.s_addr=htonl(INADDR_ANY);
if (setsockopt(fd, IPPROTO_IP, IP_DROP_MEMBERSHIP, &mreq, sizeof(mreq)) < 0) {
- return False();
+ return ThrowException(ErrnoException(errno, "socket"));
}
return True();
@@ -113,7 +113,7 @@ namespace node_multicast {
u_char ttl = args[1]->Int32Value();
if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, sizeof(ttl)) < 0) {
- return False();
+ return ThrowException(ErrnoException(errno, "socket"));
}
return True();
@@ -138,7 +138,7 @@ namespace node_multicast {
memcpy(ifnamestr, *ifname, ifname.length());
ifaddr = inet_addr(ifnamestr);
if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_IF, &ifaddr, sizeof(ifaddr)) < 0) {
- return False();
+ return ThrowException(ErrnoException(errno, "socket"));
}
return True();
View
39 mdgram.js
@@ -1,35 +1,38 @@
var binding = require('./bindings');
var dgram=require("dgram");
-var Socket={};
-Socket.joinGroup = function(group) {
+var Socket=dgram.Socket;
+exports.Socket = Socket;
+exports.createSocket = function (type, listener) {
+ if (type != 'udp4') {
+ throw new TypeError("Invalid Multicast Socket-Type: "+type);
+ }
+ return new Socket(type, listener);
+};
+
+Socket.prototype.joinGroup = function(group) {
if (!this.fd) throw new Error('Not running');
- return binding.joinGroup(this.fd, group+"");
+ if(binding.joinGroup(this.fd, group+"")) return;
+ throw new Error("Could not joinGroup: "+group);
};
-Socket.leaveGroup = function(group) {
+Socket.prototype.leaveGroup = function(group) {
if (!this.fd) throw new Error('Not running');
- return binding.leaveGroup(this.fd, group+"");
+ if (binding.leaveGroup(this.fd, group+"")) return;
+ throw new Error("Could not leaveGroup: "+group);
};
-Socket.setMulticastTTL = function(arg) {
+Socket.prototype.setMulticastTTL = function(arg) {
if (!this.fd) throw new Error('Not running');
var newttl = parseInt(arg,10);
if (newttl > 0 && newttl < 256) {
- return binding.setTTL(this.fd, newttl);
+ if(binding.setTTL(this.fd, newttl)) return;
+ throw new Error("Could not setMulticastTTL: "+group);
} else {
throw new Error("New MulticastTTL must be between 1 and 255");
}
};
-Socket.setMulticastInterface = function(arg) {
+Socket.prototype.setMulticastInterface = function(arg) {
if (!this.fd) throw new Error('Not running');
- return binding.setInterface(this.fd, arg+"");
-};
-
-exports.createSocket = function() {
- var socket = dgram.createSocket("udp4");
- socket.joinGroup = Socket.joinGroup;
- socket.leaveGroup = Socket.leaveGroup;
- socket.setMulticastTTL = Socket.setMulticastTTL;
- socket.setMulticastInterface = Socket.setMulticastInterface;
- return socket;
+ if (binding.setInterface(this.fd, arg+"")) return;
+ throw new Error("Could not setMulticastInterface: "+group);
};
View
9 package.json
@@ -1,5 +1,5 @@
{
- "name" : "multicast",
+ "name" : "mdgram",
"description" : "Provide UDP-Multicast Sockets",
"homepage" : "http://sannis.github.com/node-mysql-libmysqlclient",
"version" : "0.0.1",
@@ -9,16 +9,15 @@
"contributors" :[
{ "name": "Philipp Dunkel", "email": "phidelta@phideltacity.net" }
],
- "bugs" : { "web" : "http://github.com/Sannis/node-mysql-libmysqlclient/issues" },
+ "bugs" : { "web" : "http://github.com/phidelta/NodeJS-UDP-Multicast" },
"licenses" : [ { "type" : "MIT" } ],
"repositories" : [
- { "type" : "git", "url" : "http://github.com/Sannis/node-mysql-libmysqlclient.git" }
+ { "type" : "git", "url" : "http://github.com/phidelta/NodeJS-UDP-Multicast.git" }
],
- "main" : "./multicast.js",
+ "main" : "./mdgram.js",
"scripts" : {
"build" : "node-waf configure build",
"test" : "node-waf test",
- "doc" : "node-waf doc"
},
"engines" : { "node" : ">=0.2.3" }
}
View
2  wscript
@@ -15,7 +15,7 @@ def configure(conf):
def build(bld):
obj = bld.new_task_gen('cxx', 'shlib', 'node_addon')
obj.target = 'bindings'
- obj.source = 'multicast.cc'
+ obj.source = 'mdgram.cc'
def shutdown():
# HACK to get bindings.node out of build directory.
Please sign in to comment.
Something went wrong with that request. Please try again.