Lua Socket: Difference between revisions

From Spring
Jump to navigationJump to search
Abma (talk | contribs)
Abma (talk | contribs)
Line 47: Line 47:
==Notes / known issues / TODO ==
==Notes / known issues / TODO ==


* only ipv4 is supported (could be solved by using unstable luasocket2: http://code.matthewwild.co.uk/luasocket2-hg/)
* only ipv4 is supported (could be solved by using unstable luasocket2: http://code.matthewwild.co.uk/luasocket2-hg/) or https://github.com/diegonehab/luasocket (seems to be the more official)
* dns resolving is blocking, solutions: worker thread or some lib:
* dns resolving is blocking, solutions: worker thread or some lib:
** adns http://www.chiark.greenend.org.uk/~ian/adns/
** adns http://www.chiark.greenend.org.uk/~ian/adns/

Revision as of 09:15, 4 June 2012

LuaSockets allow a widget to use tcp/udp sockets. With luasockets you can create a client or a server connecting to a server and transfering some data.

There are many possibilties what could be done with luasockets in spring, some ideas:

  • webserver that shows all files in VFS
  • telnet console, that allows control of spring
  • statistics webpage
  • ingame widget updater
  • ingame news pages
  • ...

config

All LuaSocket related config is readonly for LuaWidgets. They can be only changed through unitsync.

As default, socket access is restricted, as default no connections are allowed. To allow a connection / sending a packet, the destination has to the corresponding allow rule. For example, if a lua widget wants to connect to springrts.com at port 80,

TCPAllowConnect springrts.com:80

has to be set.


possible config values

LuaSocketEnabled = 1 Default is 0 means, all Socket functions are disabled
TCPAllowConnect allow TCP-connections to the listed hosts, for example: "springrts.com:80 springfiles.com:80" which allows luasockets to connect to springrts.com at port 80 and springfiles.com at port 80.
TCPAllowListen Server TCP-sockets are allowed on this port, for example: "localhost:1234 0.0.0.0:12345"
UDPAllowConnect see TCPAllowConnect
UDPAllowConnect see TCPAllowListen

example code

Notes / known issues / TODO

Error in Initialize(): [string "LuaUI/Widgets/luasocket.lua"]:65:
attempt to index upvalue 'socket' (a nil value)

you maybe need to add to system.lua: socket = socket,

documentation

links

lua sockets in spring - original thread Lua Lobby / Socket - some code pieces for connecting to spring lobby server & protocol