View topic - lua sockets in spring


All times are UTC + 1 hour


Post new topic Reply to topic  [ 26 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: lua sockets in spring
PostPosted: 23 Jan 2012, 07:38 
Spring Developer

Joined: 31 May 2009, 23:08
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


Last edited by abma on 18 Feb 2012, 05:47, edited 1 time in total.
Top
 Offline Profile  
 
PostPosted: 30 Jan 2012, 00:55 
Spring Developer

Joined: 31 May 2009, 23:08
...


Last edited by abma on 18 Feb 2012, 05:48, edited 1 time in total.
Top
 Offline Profile  
 
PostPosted: 30 Jan 2012, 07:20 
User avatar

Joined: 22 Feb 2006, 01:02
Location: cheap kitchen
small question, in the example don't you risk "comparing nil with string blabla" by doing
Code:
local readable, writeable, error = socket.select(set, set, 0)
if error=="timeout" then <-
return
end
because http://w3.impa.br/~diego/software/luasocket/socket.html says error returned by socket.select can also be nil:
Quote:
The error message is "timeout" if a timeout condition was met and nil otherwise.

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)
Top
 Offline Profile  
 
PostPosted: 30 Jan 2012, 09:44 
Spring Developer

Joined: 31 May 2009, 23:08
knorke wrote:
small question, in the example don't you risk "comparing nil with string blabla" by doing


yeah, that was wrong, i fixed it, thanks! the widget is still a proof of concept, it will stabelize over time...


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)


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.

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.
Top
 Offline Profile  
 
PostPosted: 31 Jan 2012, 02:01 
User avatar

Joined: 22 Feb 2006, 01:02
Location: cheap kitchen
Image
wow its the captain himself.
Top
 Offline Profile  
 
PostPosted: 01 Feb 2012, 04:17 
Spring Developer

Joined: 31 May 2009, 23:08
nice! :-)
Top
 Offline Profile  
 
PostPosted: 01 Feb 2012, 07:59 
User avatar

Joined: 22 Feb 2006, 01:02
Location: cheap kitchen
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.
Top
 Offline Profile  
 
PostPosted: 03 Feb 2012, 12:33 
Spring Developer

Joined: 31 May 2009, 23:08
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)


thanks for reporting. that was a feature ;-). now it should work (fixed by https://github.com/spring/spring/commit ... 43164a5a16 )
Top
 Offline Profile  
 
PostPosted: 28 Mar 2012, 10:54 
Spring Developer

Joined: 31 May 2009, 23:08
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!
Top
 Offline Profile  
 
PostPosted: 14 May 2012, 22:17 

Joined: 10 Nov 2011, 21:42
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?
Top
 Offline Profile  
 
PostPosted: 14 May 2012, 22:30 
Spring Developer

Joined: 31 May 2009, 23:08
Quote:
Are we expected to uncomment this?

no, this line can be removed (i already removed in locally the repo, will push soon).

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


are you using a development version of spring? the current stable version doesn't include luasocket support... spring 89 will contain it.
Top
 Offline Profile  
 
PostPosted: 14 May 2012, 22:44 

Joined: 10 Nov 2011, 21:42
Fixed... What I needed to do was add this to my system.lua fie:
socket = socket,
Top
 Offline Profile  
 
PostPosted: 14 May 2012, 22:58 
Spring Developer

Joined: 31 May 2009, 23:08
aah, thanks. added to the wiki page.
Top
 Offline Profile  
 
PostPosted: 15 May 2012, 00:11 

Joined: 10 Nov 2011, 21:42
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?
Top
 Offline Profile  
 
PostPosted: 15 May 2012, 00:28 
Spring Developer

Joined: 31 May 2009, 23:08
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

Code:
LuaSocketEnabled=1
TCPAllowConnect=springrts.com:80


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.
Top
 Offline Profile  
 
PostPosted: 15 May 2012, 02:42 
Spring Developer

Joined: 31 May 2009, 23:08
http://springrts.com/dl/buildbot/defaul ... -gd13f581/
works for me on windows...

weird bug: https://github.com/spring/spring/commit ... c2b#L0R219 :-/
Top
 Offline Profile  
 
PostPosted: 30 May 2012, 23:34 

Joined: 12 Apr 2011, 09:00
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
Top
 Offline Profile  
 
PostPosted: 25 Jun 2012, 18:23 

Joined: 25 Jun 2012, 18:18
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?
Top
 Offline Profile  
 
PostPosted: 25 Jun 2012, 18:41 
Spring Developer

Joined: 31 May 2009, 23:08
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?


no, that would cause a desync. you've to use something like this:
viewtopic.php?t=21792&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))
Top
 Offline Profile  
 
PostPosted: 25 Jun 2012, 19:03 

Joined: 25 Jun 2012, 18:18
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.)


Attachments:
Spring Remote Network.pdf [16.2 KiB]
Downloaded 50 times
Top
 Offline Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 26 posts ]  Go to page 1, 2  Next

All times are UTC + 1 hour


Who is online

Users browsing this forum: Exabot [Bot] and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group
Site layout created by Roflcopter et al.