It is highly advisable that you stick to NSE sockets for network I/O operations when creating your own scripts. The libraries involved have been thoroughly tested and will work uniformly across platforms. NSE sockets are handled internally by the Nsock
library, which offers advantages such as transparent parallelism by performing non-blocking I/O operations. When programmers decide to use what appear to be blocking calls, NSE in the background simply fires a callback after a certain time so that they will never block scripts completely.
NSE sockets can be used in two different ways. Using a classic connect style socket which opens the connection, sends or receives data, and closes the connection and using a powerful Libpcap interface to process raw packets. In either case, Nsock
is responsible for handling them internally via the nmap
NSE library (http://nmap.org/nsedoc/lib/nmap.html).
Finally, don't forget to use the --packet-trace
Nmap option when developing scripts...