What can be the datagram maximum size It really depends on the network it

What can be the datagram maximum size it really

This preview shows page 76 - 79 out of 142 pages.

What can be the datagram maximum size? It really depends on the network it travels through. The UDP header allows up to 65535 bytes of data, but if you are sending a packet across an Ethernet network, for instance, the Ethernet MTU is 1500 bytes, limiting the maximum datagram size. Also, some routers will attempt to fragment a large UDP packet into 512 byte chunks. UDP Exercises Exercise 1 Create a UDP server that echoes the messages it receives back into the origin socket.
Image of page 76
Child processes On Node you can spawn child processes, which can be another Node process or any process you can launch from the command line. For that you will have to provide the command and arguments to execute it. You can either spawn and live along side the process (spawn), or you can wait until it exits (exec). Executing commands You can then launch another process and wait for it to finish like this: 1 var exec = require( 'child_process' ).exec; 2 3 exec( 'cat *.js wc -l' , function (err, stdout, stderr) { 4 if (err) { 5 console.log( 'child process exited with error code ' + err.code); 6 return ; 7 } 8 console.log(stdout); 9 }); Here on line 3 we are passing in “ cat *.js wc -l ” as the command, the first argument to the exec invokation. We are then passing as the second argument a callback function that will be invoked once the exec has finished. If the child process returned an error code, the first argument of the callback will contain an instance of Error, with the code property set to the child exit code. If not, the output of stdout and stderr will be collected and be offered to us as strings. You can also pass an optional options argument between the command and the callback function like this: 1 var options = {timeout : 10000 }; 2 exec( 'cat *.js wc -l' , options, function (err, stdout, stderr) { 3 //... 4 }); The available options are:
Image of page 77
Child processes 67 encoding : the expected encoding for the child output. Defaults to ‘utf8’; timeout : the timeout in milliseconds for the execution of the command. Defaults to 0, which does not timeout; maxBuffer : specifies the maximum size of the output allowed on stdout or stderr. If exceeded, the child is killed. Defaults to 200 * 1024; killSignal : the signal to be sent to the child if it times out or exceeds the output buffers. Identified as a string; cwd : current working directory; env : environment variables to be passed into the child process. Defaults to null. On the killSignal option you can pass a string identifying the name of the signal you wish to send to the target process. Signals are identified in node as strings. For a complete list of strings type on your shell: 1 $ man signal Scroll down, and you will see a list of constants representing the signals. Those are the strings used in Node. Spawning processes You can spawn a new child process based on the child_process.spawn function like this: 1 var spawn = require( 'child_process' ).spawn; 2 3 var child = spawn( 'tail' , [ '-f' , '/var/log/system.log' ] ); 4 child.stdout.on( 'data' , function (data) { 5 console.log( 'stdout: ' + data); 6 }); Here we are spawning a child process to run the “tail” command, passing in as arguments “-f” and “/var/log/system.log”. This “tail” command will monitor the file “/var/log/system.log” - if it exists -
Image of page 78
Image of page 79

You've reached the end of your free preview.

Want to read all 142 pages?

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture