Enabling socket communication with LuaSocket

A few weeks ago, I’ve been helping a user on the #openvibe IRC channel, to enable socket communication within lua. This post aims at helping interested people do the same :)

LuaSocket is an addition of lua that actually enables socket communication within lua. It provides low level functionalities such as TCP / UDP communication, but also provides higher level services such as HTTP or FTP clients. Interested readers can find a detailed introduction on the project’s website.

Windows

Installing on Windows is really easy :

If you are building OpenViBE from sources, its binary folder is actually :

<path-to-your-source-tree>/dist/bin

If you are using a precompiled version of OpenViBE, its binary folder is actually :

<path-where-you-installed-it>/bin

Linux

Installing on Linux is almost as easy :) :

  • Download the luasocket-2.0.2.tar.gz source package.
    wget http://luaforge.net/frs/download.php/2664/luasocket-2.0.2.tar.gz
  • Extract this archive in a temporary folder.
    tar xvfz luasocket-2.0.2.tar.gz
  • Patch the Makefile’s configuration file to point to the location where you installed OpenViBE dependencies. This can be achieved by appending the following lines to the config file :
    LUAINC=-I<path>/scripts/software/include
    INSTALL_TOP_SHARE=<path>/scripts/software/share/lua/5.1
    INSTALL_TOP_LIB=<path>/scripts/software/lib/lua/5.1

    Don’t forget to replace <path> with the appropriate path where you checked OpenViBE out.

  • Compile and install the package :
    make
    make install
  • You now have to tell lua to look to the right location in order to find this module appending a few lines to the linux-dependencies script :
    export LUA_PATH=<path>/scripts/software/share/lua/5.1/?.lua\;?.lua
    export LUA_CPATH=<path>/scripts/software/lib/lua/5.1/?.so\;?.so

    Again, don’t forget to replace <path> with the appropriate path where you checked OpenViBE out.

Testing

You can now check that everything is fine within the Lua Stimulator box thanks to this basic script :

socket = require(“socket”)
print(socket._VERSION)

You should see the following message in your console :

LuaSocket 2.0.2

I also got the cookie message from my SSH server using the following script :

client=socket.tcp()
client:connect(“localhost”, 22)
cookie=client:receive()
print(cookie)

This prints the following message :

SSH-2.0-OpenSSH_5.5p1 Debian-4ubuntu4

Closing words

This ability of the Lua Stimulator box to connect to any application through network will probably deprecate a lot of the Button VRPN Server boxes that we have used so far to communicate with VR applications… It is probably much more handy and opens perspectives for more complex but still configurable communications between OpenViBE and outside world.

Comments are closed.