@@ -4,57 +4,29 @@ const assert = require('assert');
4
4
const dgram = require ( 'dgram' ) ;
5
5
const server_port = common . PORT ;
6
6
const message_to_send = 'A message to send' ;
7
- let client ;
8
- let timer ;
9
7
10
8
const 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 ) => {
14
10
assert . strictEqual ( rinfo . address , common . localhostIPv4 ) ;
15
11
assert . strictEqual ( msg . toString ( ) , message_to_send . toString ( ) ) ;
16
12
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 ) => {
25
17
assert . strictEqual ( rinfo . address , common . localhostIPv4 ) ;
26
18
assert . strictEqual ( rinfo . port , server_port ) ;
27
19
assert . strictEqual ( msg . toString ( ) , message_to_send . toString ( ) ) ;
28
20
client . close ( ) ;
29
21
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 ( ( ) => { } ) ) ;
56
31
server . bind ( server_port ) ;
57
32
58
- timer = setTimeout ( function ( ) {
59
- throw new Error ( 'Timeout' ) ;
60
- } , common . platformTimeout ( 200 ) ) ;
0 commit comments