@@ -4,57 +4,29 @@ const assert = require('assert');
44const dgram = require ( 'dgram' ) ;
55const server_port = common . PORT ;
66const message_to_send = 'A message to send' ;
7- let client ;
8- let timer ;
97
108const server = dgram . createSocket ( 'udp4' ) ;
11- server . on ( 'message' , function ( msg , rinfo ) {
12- console . log ( 'server got: ' + msg +
13- ' from ' + rinfo . address + ':' + rinfo . port ) ;
9+ server . on ( 'message' , common . mustCall ( ( msg , rinfo ) => {
1410 assert . strictEqual ( rinfo . address , common . localhostIPv4 ) ;
1511 assert . strictEqual ( msg . toString ( ) , message_to_send . toString ( ) ) ;
1612 server . send ( msg , 0 , msg . length , rinfo . port , rinfo . address ) ;
17- } ) ;
18- server . on ( 'listening' , function ( ) {
19- var address = server . address ( ) ;
20- console . log ( 'server is listening on ' + address . address + ':' + address . port ) ;
21- client = dgram . createSocket ( 'udp4' ) ;
22- client . on ( 'message' , function ( msg , rinfo ) {
23- console . log ( 'client got: ' + msg +
24- ' from ' + rinfo . address + ':' + address . port ) ;
13+ } ) ) ;
14+ server . on ( 'listening' , common . mustCall ( ( ) => {
15+ const client = dgram . createSocket ( 'udp4' ) ;
16+ client . on ( 'message' , common . mustCall ( ( msg , rinfo ) => {
2517 assert . strictEqual ( rinfo . address , common . localhostIPv4 ) ;
2618 assert . strictEqual ( rinfo . port , server_port ) ;
2719 assert . strictEqual ( msg . toString ( ) , message_to_send . toString ( ) ) ;
2820 client . close ( ) ;
2921 server . close ( ) ;
30- } ) ;
31- client . send (
32- message_to_send ,
33- 0 ,
34- message_to_send . length ,
35- server_port ,
36- 'localhost' ,
37- function ( err ) {
38- if ( err ) {
39- console . log ( 'Caught error in client send.' ) ;
40- throw err ;
41- }
42- }
43- ) ;
44- client . on ( 'close' ,
45- function ( ) {
46- if ( server . fd === null ) {
47- clearTimeout ( timer ) ;
48- }
49- } ) ;
50- } ) ;
51- server . on ( 'close' , function ( ) {
52- if ( client . fd === null ) {
53- clearTimeout ( timer ) ;
54- }
55- } ) ;
22+ } ) ) ;
23+ client . send ( message_to_send ,
24+ 0 ,
25+ message_to_send . length ,
26+ server_port ,
27+ 'localhost' ) ;
28+ client . on ( 'close' , common . mustCall ( ( ) => { } ) ) ;
29+ } ) ) ;
30+ server . on ( 'close' , common . mustCall ( ( ) => { } ) ) ;
5631server . bind ( server_port ) ;
5732
58- timer = setTimeout ( function ( ) {
59- throw new Error ( 'Timeout' ) ;
60- } , common . platformTimeout ( 200 ) ) ;
0 commit comments