Permalink
Browse files

Add hello world client & server over udp

  • Loading branch information...
1 parent d063623 commit 2451c900084afcf85be7d6538d06c95d4506b3bf @pquerna committed Dec 13, 2010
Showing with 30 additions and 0 deletions.
  1. +14 −0 udp/hello-client.js
  2. +16 −0 udp/hello-server.js
View
@@ -0,0 +1,14 @@
+/* This code is PUBLIC DOMAIN, and is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND. See the accompanying
+ * LICENSE file.
+ */
+
+var Buffer = require('buffer').Buffer;
+var dgram = require('dgram')
+
+var sock = dgram.createSocket("udp4");
+
+var buf = new Buffer("hello world");
+
+sock.sendto(buf, 0, buf.length, 8000, "127.0.0.1");
+sock.close();
View
@@ -0,0 +1,16 @@
+/* This code is PUBLIC DOMAIN, and is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND. See the accompanying
+ * LICENSE file.
+ */
+
+var Buffer = require('buffer').Buffer;
+var dgram = require('dgram')
+log = require('sys').log
+
+sock = dgram.createSocket("udp4", function (msg, rinfo) {
+ log('got message from '+ rinfo.address +':'+ rinfo.port);
+ log('data len: '+ rinfo.size + " data: "+ msg.toString('ascii', 0, rinfo.size));
+ sock.close();
+});
+
+sock.bind(8000, '0.0.0.0');

0 comments on commit 2451c90

Please sign in to comment.