Andreas Rozek Hints for Reading List of Recent Changes Guestbook Entry Contact the Author  Deutsche Version  HomePage Previous Topic Next Topic  First Page of Current Topic Next Page Previous Page

Socket_00 - a first simple LuaSocket Script

"Socket_00" tests the successful integration of the LuaSocket package and (for that purpose) determines both the numeric IP address and the symbolic host name of the local system.

The program itself is extremely simple and does not need any further explanation. However, upon invocation, it may take several seconds for the "DNS lookup" to terminate (either successfully or unsuccessfully).

"Socket_00" should be invoked without any command line arguments

  lua Socket_00.lua

and - after a brief pause of reasoning - produces output similar to the following:

  Socket_00 - tries to retrieve the local host name or IP address

  trying 'tohostname("127.0.0.1")'...(may block for several seconds)
  ...failed, reason: "unable to resolve host name"

  trying 'toip("localhost")'...(may block for several seconds)
    Address      = 127.0.0.1
    canonic name =        ksat24
    alias list   = (empty)
    address list = 127.0.0.1

The actual display may vary considerably from system to system.

Source Code

The source code of this example is available for download:

References

[1] Roberto Ierusalimschy, Luiz Henrique de Figueiredo, Waldemar Celes
Reference Manual of the Programming Language Lua 4.0
(see http://www.lua.org/manual)
the official reference manual contains any relevatn information about the language itself, the set of standard libraries and its interface to the run-time environment;
[2] Diego Nehab
LuaSocket - IPv4 Sockets support for the Lua language
(see http://www.tecgraf.puc-rio.br/~diego/luasocket)
LuaSocket provides support for a number of important IPv4 functions. From the given web page you will be referred to a description of LuaSocket as well as to source code and binary distributions;

Disclaimer

Please, consider also the author's Disclaimer!

http://www.Andreas-Rozek.de/Lua/Acquainting/Socket_00_en.html    (last Modification: 15.04.2002)