lua sockets in spring
Moderator: Moderators
lua sockets in spring
LuaSockets allow Lua Widgets use the socket interface. It allows to connect/bind a tcp/udp socket.
For details, see the wikipage:
http://springrts.com/wiki/LuaSocket
For details, see the wikipage:
http://springrts.com/wiki/LuaSocket
Last edited by abma on 18 Feb 2012, 05:47, edited 1 time in total.
Re: lua sockets in spring
small question, in the example don't you risk "comparing nil with string blabla" by doing
because http://w3.impa.br/~diego/software/luasocket/socket.html says error returned by socket.select can also be nil:
When the widget/lua ui is reloaded, are all sockets closed or could there be funny effects?
(i havent looked at it yet but might later when coming home)
Code: Select all
local readable, writeable, error = socket.select(set, set, 0)
if error=="timeout" then <-
return
end
So atm everything is unrestricted? (just asking so I do not wonder if I did something wrong or being blocked)The error message is "timeout" if a timeout condition was met and nil otherwise.
When the widget/lua ui is reloaded, are all sockets closed or could there be funny effects?
(i havent looked at it yet but might later when coming home)
Re: lua sockets in spring
yeah, that was wrong, i fixed it, thanks! the widget is still a proof of concept, it will stabelize over time...knorke wrote:small question, in the example don't you risk "comparing nil with string blabla" by doing
connections are restricted, see http://springrts.com/wiki/LuaSocket#config_settings . access to the sockets in general aren't restricted, thinks like a http-server should be possible.knorke wrote: So atm everything is unrestricted? (just asking so I do not wonder if I did something wrong or being blocked)
When the widget/lua ui is reloaded, are all sockets closed or could there be funny effects?
(i havent looked at it yet but might later when coming home)
if you want to connect to example.org port 80, you've to set LuaSocketEnabled=1 and TCPAllowConnect = example.org:80 in .springrc. i made that more clear in the example.
These values are also read-only, a lua-widget can't change them, and i hopefully already disabled most/all ways to override that, maybe see http://springrts.com/wiki/LuaSocket#Not ... s_.2F_TODO for that.
Re: lua sockets in spring
wow its the captain himself.
Re: lua sockets in spring
btw, in spring.exe changing the new settings like LuaSocketEnabled=0/1 does not work. (enter value, click ok, value is not updated)
It works with springsettings.conf though.
It works with springsettings.conf though.
Re: lua sockets in spring
thanks for reporting. that was a feature . now it should work (fixed by https://github.com/spring/spring/commit ... 43164a5a16 )knorke wrote:btw, in spring.exe changing the new settings like LuaSocketEnabled=0/1 does not work. (enter value, click ok, value is not updated)
Re: lua sockets in spring
the luasocket branch is merged into spring develop, i also updated the wiki page:
http://springrts.com/wiki/LuaSocket
if you find bugs, please report!
http://springrts.com/wiki/LuaSocket
if you find bugs, please report!
Re: lua sockets in spring
Hello I am having trouble getting luasocket.lua example to work.
I am confused about this line right here.
--VFS.Include(LUAUI_DIRNAME .. "Widgets/socket/socket.lua")
Are we expected to uncomment this? When I leave it uncommented I
get this error:
Error in Initialize(): [string "LuaUI/Widgets/luasocket.lua"]:65: attempt to index upvalue 'socket' (a nil value)
I searched around and found socket.lua file and put it into Widgets/socket/
Failed to load: luasocket.lua (error = 2, LuaUI/Widgets/socket/socket.lua, [string "LuaUI/Widgets/socket/socket.lua"]:15: attempt to index global 'socket' (a nil value))
What am I doing wrong?
I am confused about this line right here.
--VFS.Include(LUAUI_DIRNAME .. "Widgets/socket/socket.lua")
Are we expected to uncomment this? When I leave it uncommented I
get this error:
Error in Initialize(): [string "LuaUI/Widgets/luasocket.lua"]:65: attempt to index upvalue 'socket' (a nil value)
I searched around and found socket.lua file and put it into Widgets/socket/
Failed to load: luasocket.lua (error = 2, LuaUI/Widgets/socket/socket.lua, [string "LuaUI/Widgets/socket/socket.lua"]:15: attempt to index global 'socket' (a nil value))
What am I doing wrong?
Re: lua sockets in spring
no, this line can be removed (i already removed in locally the repo, will push soon).Are we expected to uncomment this?
are you using a development version of spring? the current stable version doesn't include luasocket support... spring 89 will contain it.Voidness wrote:Error in Initialize(): [string "LuaUI/Widgets/luasocket.lua"]:65: attempt to index upvalue 'socket' (a nil value)
Re: lua sockets in spring
Fixed... What I needed to do was add this to my system.lua fie:
socket = socket,
socket = socket,
Re: lua sockets in spring
aah, thanks. added to the wiki page.
Re: lua sockets in spring
Hello I am still having problems getting luasocket.lua example to work.
I am trying to connect to springrts.com:80
I get this error in :
[f=0000000] Error: Socket already closed
When I call SocketConnect
Any ideas?
I am trying to connect to springrts.com:80
I get this error in :
[f=0000000] Error: Socket already closed
When I call SocketConnect
Any ideas?
Re: lua sockets in spring
thats strange. are you on windows?
i slightly changed luasocket.lua. now it gets the latest version of spring from springrts.com. I wonder why i did not make this as example before...
https://github.com/spring/spring/commit ... ccff942df8
to get it work, you've to set
in .springrc, then it should work... do you have a firewall that blocks spring maybe?
edit: your settings are fine, without it, you would get "Error: Access to 'springrts.com:80' denied". damnit, there is the error:
https://github.com/spring/spring/blob/d ... t.cpp#L222
this works on linux, but not on win32.. will need a bit to fix that.
i slightly changed luasocket.lua. now it gets the latest version of spring from springrts.com. I wonder why i did not make this as example before...
https://github.com/spring/spring/commit ... ccff942df8
to get it work, you've to set
Code: Select all
LuaSocketEnabled=1
TCPAllowConnect=springrts.com:80
edit: your settings are fine, without it, you would get "Error: Access to 'springrts.com:80' denied". damnit, there is the error:
https://github.com/spring/spring/blob/d ... t.cpp#L222
this works on linux, but not on win32.. will need a bit to fix that.
Re: lua sockets in spring
http://springrts.com/dl/buildbot/defaul ... -gd13f581/
works for me on windows...
weird bug: https://github.com/spring/spring/commit ... c2b#L0R219 :-/
works for me on windows...
weird bug: https://github.com/spring/spring/commit ... c2b#L0R219 :-/
Re: lua sockets in spring
Voidness (previous poster on this thread) and I developed a lua sockets widget that listens for tuio touch events.
Posted on http://springrts.com/phpbb/viewtopic.php?f=12&t=26900
Posted on http://springrts.com/phpbb/viewtopic.php?f=12&t=26900
Re: lua sockets in spring
I got some basic LuaSocket stuff running in a widget perfectly, but when I try it in a gadget I get the error "attempt to index global 'socket' (a nil value)". Is there a way I can get gadgets to support LuaSocket?
Re: lua sockets in spring
no, that would cause a desync. you've to use something like this:evan wrote:I got some basic LuaSocket stuff running in a widget perfectly, but when I try it in a gadget I get the error "attempt to index global 'socket' (a nil value)". Is there a way I can get gadgets to support LuaSocket?
http://springrts.com/phpbb/viewtopic.ph ... 2&p=406930
and/or
http://springrts.com/wiki/Lua_sync_to_unsync
some more keywords:
SendToUnsynced
SendLuaRulesMsg
i hope thats a point to start..
what do you want to do? maybe it can be done within a widget?
(note: i'm bad in lua, maybe there are better solutions)
also imo thats a good question for here: http://answers.springlobby.info/ (something like "How can i send data from a widget to a gadget? (unsynced -> synced))
Re: lua sockets in spring
We're creating a game where each unit is represented by a real-life node. (For testing we're using an array of routers, but these will be remote control vehicles eventually.) Commands can only be issued to units in the game if their real-life counterparts are connected via an ad-hoc network. So the goal was to intercept a command (AllowCommand), send it out to the network as a UDP packet, and if/when the target node receives the command, send it back to the game and insert it into the command queue.
I've attached a diagram that illustrates our goal. The C&C node is a "home base" kind of unit where all commands are issued from. (You can ignore the difference between wifi and VIA connections.)
I've attached a diagram that illustrates our goal. The C&C node is a "home base" kind of unit where all commands are issued from. (You can ignore the difference between wifi and VIA connections.)
- Attachments
-
- Spring Remote Network.pdf
- (16.2 KiB) Downloaded 59 times