mirror of https://github.com/lukechilds/node.git
Matt Ranney
15 years ago
committed by
Ryan Dahl
8 changed files with 547 additions and 252 deletions
@ -0,0 +1,52 @@ |
|||
require("../common"); |
|||
|
|||
var Buffer = require("buffer").Buffer, |
|||
fs = require("fs"), |
|||
dgram = require("dgram"), server, client, |
|||
server_port = 20989, |
|||
message_to_send = new Buffer("A message to send"), |
|||
timer; |
|||
|
|||
server = dgram.createSocket("udp4"); |
|||
server.on("message", function (msg, rinfo) { |
|||
console.log("server got: " + msg + " from " + rinfo.address + ":" + rinfo.port); |
|||
assert.strictEqual(rinfo.address, "127.0.0.1"); |
|||
assert.strictEqual(msg.toString(), message_to_send.toString()); |
|||
server.send(msg, 0, msg.length, rinfo.port, rinfo.address); |
|||
}); |
|||
server.on("listening", function () { |
|||
var address = server.address(); |
|||
console.log("server is listening on " + address.address + ":" + address.port); |
|||
client = dgram.createSocket("udp4"); |
|||
client.on("message", function (msg, rinfo) { |
|||
console.log("client got: " + msg + " from " + rinfo.address + ":" + address.port); |
|||
assert.strictEqual(rinfo.address, "127.0.0.1"); |
|||
assert.strictEqual(rinfo.port, server_port); |
|||
assert.strictEqual(msg.toString(), message_to_send.toString()); |
|||
client.close(); |
|||
server.close(); |
|||
}); |
|||
client.send(message_to_send, 0, message_to_send.length, server_port, "localhost", function (err, bytes) { |
|||
if (err) { |
|||
console.log("Caught error in client send."); |
|||
throw err; |
|||
} |
|||
console.log("client wrote " + bytes + " bytes."); |
|||
assert.strictEqual(bytes, message_to_send.length); |
|||
}); |
|||
client.on("close", function () { |
|||
if (server.fd === null) { |
|||
clearTimeout(timer); |
|||
} |
|||
}); |
|||
}); |
|||
server.on("close", function () { |
|||
if (client.fd === null) { |
|||
clearTimeout(timer); |
|||
} |
|||
}); |
|||
server.bind(server_port); |
|||
|
|||
timer = setTimeout(function () { |
|||
throw new Error("Timeout"); |
|||
}, 200); |
@ -0,0 +1,56 @@ |
|||
require("../common"); |
|||
|
|||
var Buffer = require("buffer").Buffer, |
|||
fs = require("fs"), |
|||
dgram = require("dgram"), server, client, |
|||
server_path = "/tmp/dgram_server_sock", |
|||
messages_to_send = [ |
|||
new Buffer("First message to send"), |
|||
new Buffer("Second message to send"), |
|||
new Buffer("Third message to send"), |
|||
new Buffer("Fourth message to send") |
|||
], |
|||
timer; |
|||
|
|||
server = dgram.createSocket("unix_dgram"); |
|||
server.bind(server_path); |
|||
server.messages = []; |
|||
server.on("message", function (msg, rinfo) { |
|||
console.log("server got: " + msg); |
|||
assert.strictEqual(rinfo.address, ""); // anon client sending
|
|||
server.messages.push(msg.toString()); |
|||
if (server.messages.length === messages_to_send.length) { |
|||
server.messages.forEach(function (m, i) { |
|||
assert.strictEqual(m, messages_to_send[i].toString()); |
|||
}); |
|||
server.close(); |
|||
client.close(); |
|||
} |
|||
}); |
|||
server.on("listening", function () { |
|||
console.log("server is listening"); |
|||
client = dgram.createSocket("unix_dgram"); |
|||
messages_to_send.forEach(function (m) { |
|||
client.send(m, 0, m.length, server_path, function (err, bytes) { |
|||
if (err) { |
|||
console.log("Caught error in client send."); |
|||
throw err; |
|||
} |
|||
console.log("client wrote " + bytes + " bytes."); |
|||
}); |
|||
}); |
|||
client.on("close", function () { |
|||
if (server.fd === null) { |
|||
clearTimeout(timer); |
|||
} |
|||
}); |
|||
}); |
|||
server.on("close", function () { |
|||
if (client.fd === null) { |
|||
clearTimeout(timer); |
|||
} |
|||
}); |
|||
|
|||
timer = setTimeout(function () { |
|||
throw new Error("Timeout"); |
|||
}, 200); |
@ -0,0 +1,55 @@ |
|||
require("../common"); |
|||
|
|||
var Buffer = require("buffer").Buffer, |
|||
fs = require("fs"), |
|||
dgram = require("dgram"), server, client, |
|||
server_path = "/tmp/dgram_server_sock", |
|||
client_path = "/tmp/dgram_client_sock", |
|||
message_to_send = new Buffer("A message to send"), |
|||
timer; |
|||
|
|||
server = dgram.createSocket("unix_dgram"); |
|||
server.on("message", function (msg, rinfo) { |
|||
console.log("server got: " + msg + " from " + rinfo.address); |
|||
assert.strictEqual(rinfo.address, client_path); |
|||
assert.strictEqual(msg.toString(), message_to_send.toString()); |
|||
server.send(msg, 0, msg.length, rinfo.address); |
|||
}); |
|||
server.on("listening", function () { |
|||
console.log("server is listening"); |
|||
client = dgram.createSocket("unix_dgram"); |
|||
client.on("message", function (msg, rinfo) { |
|||
console.log("client got: " + msg + " from " + rinfo.address); |
|||
assert.strictEqual(rinfo.address, server_path); |
|||
assert.strictEqual(msg.toString(), message_to_send.toString()); |
|||
client.close(); |
|||
server.close(); |
|||
}); |
|||
client.on("listening", function () { |
|||
console.log("client is listening"); |
|||
client.send(message_to_send, 0, message_to_send.length, server_path, function (err, bytes) { |
|||
if (err) { |
|||
console.log("Caught error in client send."); |
|||
throw err; |
|||
} |
|||
console.log("client wrote " + bytes + " bytes."); |
|||
assert.strictEqual(bytes, message_to_send.length); |
|||
}); |
|||
}); |
|||
client.on("close", function () { |
|||
if (server.fd === null) { |
|||
clearTimeout(timer); |
|||
} |
|||
}); |
|||
client.bind(client_path); |
|||
}); |
|||
server.on("close", function () { |
|||
if (client.fd === null) { |
|||
clearTimeout(timer); |
|||
} |
|||
}); |
|||
server.bind(server_path); |
|||
|
|||
timer = setTimeout(function () { |
|||
throw new Error("Timeout"); |
|||
}, 200); |
Loading…
Reference in new issue