-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
53 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import dgram from 'dgram' | ||
|
||
function main() { | ||
const s1 = dgram.createSocket('udp4') | ||
const s12 = dgram.createSocket('udp4') | ||
const s2 = dgram.createSocket('udp4') | ||
const TIMES = 4 * 1024 | ||
|
||
let port = null | ||
let times = 0 | ||
let received = 0 | ||
let start = 0 | ||
|
||
s2.on('message', (msg) => { | ||
times += 1 | ||
received += msg.length | ||
console.log(`received: ${times} ${received}`) | ||
|
||
if (times === TIMES) { | ||
console.log(`${Date.now() - start} elapses`) | ||
} | ||
}) | ||
|
||
function sendMsg(socket) { | ||
for (let i = 0; i < TIMES; i += 1) { | ||
socket.send(Buffer.allocUnsafe(1400), port) | ||
} | ||
} | ||
|
||
s2.bind(() => { | ||
port = s2.address().port | ||
start = Date.now() | ||
|
||
sendMsg(s1) | ||
}) | ||
} | ||
|
||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters