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_02 - Data Transfer between TCP Sockets

"Socket_02" demonstrates the data transfer between TCP sockets - for that purpose, the program creates both a server and a client socket, establishes a connection between them and transfers a short message from one socket to the other.

The program is simple enough not to require any further explanation.

"Socket_02" should be invoked without any command line arguments

  lua Socket_02.lua

and produces the following output:

  Socket_02 - a first experiment with TCP streams

  creating server socket...
  done (Address: 0.0.0.0, Port: 1284)

  creating receiver socket (contacting server)...
  done (Address: 127.0.0.1, Port: 1285)

  creating sender socket (accepting ConnReq from receiver)...
  done (Address: 127.0.0.1, Port: 1284)

  sending message...
  done

  receiving message...
  done (got "Hello")

The actually shown port numbers may vary from one invocation to the other and 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_02_en.html    (last Modification: 15.04.2002)