Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Add hello world client & server over udp

  • Loading branch information...
commit 2451c900084afcf85be7d6538d06c95d4506b3bf 1 parent d063623
Paul Querna authored December 13, 2010
14  udp/hello-client.js
... ...
@@ -0,0 +1,14 @@
  1
+/* This code is PUBLIC DOMAIN, and is distributed on an "AS IS" BASIS,
  2
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND. See the accompanying 
  3
+ * LICENSE file.
  4
+ */
  5
+
  6
+var Buffer = require('buffer').Buffer;
  7
+var dgram = require('dgram')
  8
+
  9
+var sock = dgram.createSocket("udp4");
  10
+
  11
+var buf = new Buffer("hello world");
  12
+
  13
+sock.sendto(buf, 0, buf.length, 8000, "127.0.0.1");
  14
+sock.close();
16  udp/hello-server.js
... ...
@@ -0,0 +1,16 @@
  1
+/* This code is PUBLIC DOMAIN, and is distributed on an "AS IS" BASIS,
  2
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND. See the accompanying 
  3
+ * LICENSE file.
  4
+ */
  5
+
  6
+var Buffer = require('buffer').Buffer;
  7
+var dgram = require('dgram')
  8
+log = require('sys').log
  9
+
  10
+sock = dgram.createSocket("udp4", function (msg, rinfo) {
  11
+  log('got message from '+ rinfo.address +':'+ rinfo.port);
  12
+  log('data len: '+ rinfo.size + " data: "+ msg.toString('ascii', 0, rinfo.size));
  13
+  sock.close();
  14
+});
  15
+
  16
+sock.bind(8000, '0.0.0.0');

0 notes on commit 2451c90

Please sign in to comment.
Something went wrong with that request. Please try again.