Multilanguage Perspectives


In this chapter, we ve focused on the Sockets API from the perspective of the C language, but the Sockets API is available for any worthwhile language.

Consider first the Ruby language. Ruby is an object-oriented scripting language that is growing in popularity. It s simple and clean and useful in many domains. One domain that demonstrates the simplicity of the language is in network application development.

The Daytime protocol server is shown in Listing 12.3. Ruby provides numerous classes for networking development; the one illustrated here supports TCP server sockets ( TCPserver ). At line 4, we create our server socket and bind it to the Daytime protocol server (identified by the string daytime ). At line 12, we await an incoming connection using the accept method. When one arrives, we emit the current time to the client at line 19 using the write method. Finally, the socket is closed at line 23 using the close method.

Listing 12.3: Daytime Protocol Server in the Ruby Language (on the CD-ROM at ./source/ch12/dayserv.rb )
start example
  1:  require 


GNU/Linux Application Programming
GNU/Linux Application Programming (Programming Series)
ISBN: 1584505680
EAN: 2147483647
Year: 2006
Pages: 203
Authors: M. Tim Jones

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net