Guest samuelboerhoop Share Posted September 3, 2015 When do I use the following code in lua:? tcpSocket:disconnect(); i some sample code it has been added to the sample in others not. example: -- Volume 40dB -- tcpSocket:write("MV40".."\r") fibaro:sleep(500); result, err = tcpSocket:read(); tcpSocket:disconnect(); if (err == 0) then fibaro:log("transfer OK"); fibaro:debug("transfer OK"); else fibaro:log("transfer failed"); fibaro:debug("transfer failed"); end ------------------------------------ -- HERE its not been used -- tcpSocket:write(string.char(0x53, 0x49, 0x49, 0x52, 0x41, 0x44, 0x49, 0x4f, 0x0d)); fibaro:sleep(1000); result, err = tcpSocket:read(); if (err == 0) then fibaro:log("Transfer OK: Internet Radio"); else fibaro:log("Transfer failed: extra check"); -- check source: needs 2 times... otherwise still failed... tcpSocket:write(string.char(0x53, 0x49, 0x3f, 0x0d)); fibaro:sleep(500); result, err = tcpSocket:read(); tcpSocket:write(string.char(0x53, 0x49, 0x3f, 0x0d)); fibaro:sleep(500); result, err = tcpSocket:read(); if (err == 0) then if ( trim(string.sub(result, 1, string.len(result)-9)) == 'SIIRADIO' ) then fibaro:log("Transfer OK: Internet Radio"); else fibaro:log("Transfer failed"); end else fibaro:log("Transfer failed"); end end Quote Link to post Share on other sites
1 Hiram K. Hackenbacker 2 Share Posted September 11, 2017 Where can I find a reference manual/page about this TCPsocket? I've searched the web, but all I can find is examples of one type of application (to see if a device is present on the network or not). I would like to be able to see what all of its variables do. I noticed that the readTimeout does not work as expected; the socket takes ages (>20 seconds) if no device is available, i.e. write returns an error. I would like to shorten this time-out, but changing readTimeout doesn't do the trick. Quote Link to post Share on other sites
1 lroovers 0 Share Posted October 25, 2018 Would be nice if the Fibaro adinistrator not only moves the subject, but also anwers the question about where to find documentaiton of TCPsocket Quote Link to post Share on other sites
0 j.nowacki 5 Share Posted September 4, 2015 It is of course used to close the connection and dispose the socket. It is more of a good practice question. You should close things like that. Quote Link to post Share on other sites
0 Guest samuelboerhoop Share Posted September 4, 2015 Ok If you look at the last example below where should i place the sentence: tcpSocket:disconnect(); ? After every "result, err = tcpSocket:read();" OR at the end of the last sentence of the code "result, err = tcpSocket:read();" ? Because in the example the "result, err = tcpSocket:read();" appears 3x times ? ----- Example ---- tcpSocket:write(string.char(0x53, 0x49, 0x49, 0x52, 0x41, 0x44, 0x49, 0x4f, 0x0d)); fibaro:sleep(1000); result, err = tcpSocket:read(); if (err == 0) then fibaro:log("Transfer OK: Internet Radio"); else fibaro:log("Transfer failed: extra check"); -- check source: needs 2 times... otherwise still failed... tcpSocket:write(string.char(0x53, 0x49, 0x3f, 0x0d)); fibaro:sleep(500); result, err = tcpSocket:read(); tcpSocket:write(string.char(0x53, 0x49, 0x3f, 0x0d)); fibaro:sleep(500); result, err = tcpSocket:read(); if (err == 0) then if ( trim(string.sub(result, 1, string.len(result)-9)) == 'SIIRADIO' ) then fibaro:log("Transfer OK: Internet Radio"); else fibaro:log("Transfer failed"); end else fibaro:log("Transfer failed"); end end Quote Link to post Share on other sites
0 j.nowacki 5 Share Posted September 8, 2015 It should be closed after last possible occurrence of utilizing this socket. Quote Link to post Share on other sites
0 BOT 0 Share Posted September 14, 2017 The topic has been moved from "General discussion" to "Developer". Temat został przeniesiony z "General discussion" do "Developer". Quote Link to post Share on other sites
Question
Guest samuelboerhoop
When do I use the following code in lua:?
tcpSocket:disconnect();
i some sample code it has been added to the sample in others not.
example:
Link to post
Share on other sites
6 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.