mirror of https://github.com/lukechilds/node.git
Ryan Dahl
15 years ago
1 changed files with 19 additions and 14 deletions
@ -1,43 +1,48 @@ |
|||||
common = require("../common"); |
common = require("../common"); |
||||
assert = common.assert |
assert = common.assert |
||||
|
|
||||
var Buffer = require("buffer").Buffer, |
fs = require("fs"); |
||||
fs = require("fs"), |
dgram = require("dgram"); |
||||
dgram = require("dgram"), server, client, |
|
||||
server_path = "/tmp/dgram_server_sock", |
serverPath = "/tmp/dgram_server_sock"; |
||||
client_path = "/tmp/dgram_client_sock", |
clientPath = "/tmp/dgram_client_sock"; |
||||
message_to_send = new Buffer("A message to send"); |
msgToSend = new Buffer("A message to send"); |
||||
|
|
||||
server = dgram.createSocket("unix_dgram"); |
server = dgram.createSocket("unix_dgram"); |
||||
server.on("message", function (msg, rinfo) { |
server.on("message", function (msg, rinfo) { |
||||
console.log("server got: " + msg + " from " + rinfo.address); |
console.log("server got: " + msg + " from " + rinfo.address); |
||||
assert.strictEqual(rinfo.address, client_path); |
assert.strictEqual(rinfo.address, clientPath); |
||||
assert.strictEqual(msg.toString(), message_to_send.toString()); |
assert.strictEqual(msg.toString(), msgToSend.toString()); |
||||
server.send(msg, 0, msg.length, rinfo.address); |
server.send(msg, 0, msg.length, rinfo.address); |
||||
}); |
}); |
||||
|
|
||||
server.on("listening", function () { |
server.on("listening", function () { |
||||
console.log("server is listening"); |
console.log("server is listening"); |
||||
|
|
||||
client = dgram.createSocket("unix_dgram"); |
client = dgram.createSocket("unix_dgram"); |
||||
|
|
||||
client.on("message", function (msg, rinfo) { |
client.on("message", function (msg, rinfo) { |
||||
console.log("client got: " + msg + " from " + rinfo.address); |
console.log("client got: " + msg + " from " + rinfo.address); |
||||
assert.strictEqual(rinfo.address, server_path); |
assert.strictEqual(rinfo.address, serverPath); |
||||
assert.strictEqual(msg.toString(), message_to_send.toString()); |
assert.strictEqual(msg.toString(), msgToSend.toString()); |
||||
client.close(); |
client.close(); |
||||
server.close(); |
server.close(); |
||||
}); |
}); |
||||
|
|
||||
client.on("listening", function () { |
client.on("listening", function () { |
||||
console.log("client is listening"); |
console.log("client is listening"); |
||||
client.send(message_to_send, 0, message_to_send.length, server_path, function (err, bytes) { |
client.send(msgToSend, 0, msgToSend.length, serverPath, function (err, bytes) { |
||||
if (err) { |
if (err) { |
||||
console.log("Caught error in client send."); |
console.log("Caught error in client send."); |
||||
throw err; |
throw err; |
||||
} |
} |
||||
console.log("client wrote " + bytes + " bytes."); |
console.log("client wrote " + bytes + " bytes."); |
||||
assert.strictEqual(bytes, message_to_send.length); |
assert.strictEqual(bytes, msgToSend.length); |
||||
}); |
}); |
||||
}); |
}); |
||||
|
|
||||
client.bind(client_path); |
|
||||
|
client.bind(clientPath); |
||||
}); |
}); |
||||
|
|
||||
server.bind(server_path); |
server.bind(serverPath); |
||||
|
Loading…
Reference in new issue