Chapter 16. Connecting to a Larger World
In the previous chapter, you used Lua in conjunction with web servers and web browsers—applications that take care of networking details and let you focus on dynamic content and presentation. In this chapter, you'll burrow in a little deeper and learn how to manage those communication details using Lua. The principal tool you'll use in doing this is the LuaSocket library. This package lets you connect your Lua scripts to other programs, whether those programs are running on your own machine, on another machine in your home or office network, or on an Internet server located on the other side of the globe. The facets of this library and networking in general that you'll learn about are as follows:
Building and installing LuaSocket
The rudiments of the Berkeley sockets interface
The basics of programming for the Internet
Implementing simple client and server scripts
Retaining a server-side state with coroutines
Sending and receiving e-mail
Serving and retrieving web pages
Processing content with filters
Using standard streams in a networked environment
You'll find the LuaSocket library to be a natural extension of the language that adds an entirely new dimension to your applications. At its simplest, it makes communicating with another program as easy as reading from and writing to a file.
LuaSocket is the work of Diego Nehab, an active member of the Lua community, and is made available with the same terms as Lua itself. It is widely ...