Glenn Weston Posted February 28, 2014 Report Posted February 28, 2014 Hi Pete, Just quick question on the Lua Sockets Library. I have been tinkering with Socket Comms to FSUIPC and have made some great progress. I realise the Sockets Library is one of the Standard Libraries included in Lua, Over the past few years playing with your Lua implementation in FSUIPC I have re-trained my head to do things using events due to efficiency and so forth. So I would like to ask the question if it is possible to create some event driven commands in the com library for socket communications. I may be asking way too much here and I am not at all familiar with how much work that would involve, it may not be worth the effort but would be a nice feature. With everything communicating these days over IP networks I could see some advantages for developers. I have a little project that I am trying to develop at the moment and it is beautiful not having to worry about baud rates etc, Also TCP connections are fully error checked too, so there is nothing to worry about once a connection is established. Anyhow I would be interested if there is any chance I could put in a feature request for that but it's not a critical one, I am quite happy to continue to use a Loops. I just thought I might give you something to do after coming back from Holidays !! Cheers Glenn.
Pete Dowson Posted March 3, 2014 Report Posted March 3, 2014 So I would like to ask the question if it is possible to create some event driven commands in the com library for socket communications. What events are you thinking of? The com functions already have the event ("event.com") specifically for getting control when there's received data to be processed. Anyhow I would be interested if there is any chance I could put in a feature request for that but it's not a critical one, I am quite happy to continue to use a Loops.. Rather than have any loops, better to use the timer event to wake you up to process things at regular intervals. Pete
Glenn Weston Posted March 3, 2014 Author Report Posted March 3, 2014 Thankyou for the Reply Pete, OK I guess what I am asking then is an extension to the com library that can initiate a socket sort of something like sockethandle = com.open ("port", "host") Then something like this ......... event.com(sockethandle, max, min, term, "function-name") to process the incoming data when data arrives. I hope that makes sense and you and can understand what I am asking. I am thinking in terms of the way we can do event driven scripts to handle Serial data, is it possible to do it in a similar way with TCP/UDP data. I have been looking at your Server/Slave Lua example which I modified for my own use but kept the loop at the end of the example that is used to read the data and maintain the connection. Cheers Glenn.
Pete Dowson Posted March 3, 2014 Report Posted March 3, 2014 Thankyou for the Reply Pete, OK I guess what I am asking then is an extension to the com library that can initiate a socket sort of something like sockethandle = com.open ("port", "host") Then something like this ......... event.com(sockethandle, max, min, term, "function-name") to process the incoming data when data arrives. It wouldn't be the com library, for sure. that is so wrapped up in the standard Windows i/o functions it would be a nightmare to mix into that. Looking at the existing server/client examples, I don't really see a lot wrong with using the socket options as they are. I am thinking in terms of the way we can do event driven scripts to handle Serial data, is it possible to do it in a similar way with TCP/UDP data. The serial stuff is done using a separate thread from the Lua threads to monitor the devices in real time, accumulating stuff in buffers and so one before initiating the event. The sockets stuff is different -- the thread is held suspended automatically by the accept and receive calls. So they have to be executed in the Lua thread in any case. No events are needed to awaken a thread which is merely waiting for something to occur. I have been looking at your Server/Slave Lua example which I modified for my own use but kept the loop at the end of the example that is used to read the data and maintain the connection. The loops in those aren't bad loops because the requests I mention do the suspension and the event is their return. Honestly, I don't think there's a lot to be gained in changing things. Putting another layer on top of the sockets system calls just seems to make things less efficient and less flexible. However, I've kept your suggestions on file and may look again when I find myself with less to do than usual. Regards Pete
Glenn Weston Posted March 3, 2014 Author Report Posted March 3, 2014 No problems Pete, If there is nothing to gain then you are right, just leave it as it is. It works quite well anyhow, I was just posing the question to see if it might be something that was worth looking into. Thankyou Glenn.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now