TCP - Telnet (port 23) how to receive/print a response ?

Hi

Im trying to communicate with a new HDMI Matrix device directly via IP, over port 23 and while I can send a command ok, I cant seem to capture the response thats supposed to be being sent back.

Doing some research online, I found the following post that suggests I couldnt send and receive in the same connection when its a Telnet /port 23 session ?

[url=https://stackoverflow.com/questions/32085919/lua-telnet-send-receive]sockets - Lua Telnet Send & Receive - Stack Overflow

Is that true? If so how could I get around that ?

Below are two of the LUA code examples Ive tried, but both are fine with the send, but just result in a timeout/no response.

Any help would be greatly appreciated

[code]function SYHDMIA1TO8()
local socket = require(“socket”)
local host, port = “192.168.102.252”, 23
local tcp = assert(socket.tcp())
tcp:connect(host, port);

–note the newline below
tcp:send(string.char(0x3E,0x40,0x57,0x56,0x53,0x4F,0x5B,0x31,0x5D,0x49,0x5B,0x36,0x5D,0x0D));

while true do
local s, status, partial = tcp:receive()
print(s or partial)
if status == “closed” then break end
end
tcp:close()

SYHDMIA1TO8()[/code]

[code]function SYHDMIA1TO8()
local socket = require(“socket”)
host = “192.168.102.252”
c = assert(socket.connect(host, 23))
c:settimeout(5)
local sres, serr = c:send(string.char(0x3E,0x40,0x57,0x56,0x53,0x4F,0x5B,0x31,0x5D,0x49,0x5B,0x38,0x5D,0x0D))

print(“Send:”, sres, serr)
local data, rerr = c:receive(100)
luup.log (data)
print (“Receive:”, data, rerr)
c:close()
end

SYHDMIA1TO8()
[/code]

Hi Parker,

In the example it seem they look at a proxy like function that listens both ways, that’s not simple to do in LUA.

However, sending and handling the response should be fine.

Have you tried a telnet session from your PC and see if it is not the remote device not responding? You can try to monitor the network traffic using wireshark and see what happens.

Cheers Rene

Hi @reneboer

Thanks for responding yes, I did try it with telnet and I do get a response back in the terminal window.

I used to use the #2 code (above in my first post ) with a different matrix, and that would capture the response that came back ok, its just for some reason, on this new matrix I can?t capture the responses.

Still plugging away, just tried to add a delay based on comments in other threads/forums, but I?m not sure how I do a delay while keeping the connection open, to view the results ? Here?s my latest code.

[code]function send_SYHDMIA1TO8()
local socket = require(“socket”)
host = “192.168.102.252”
c = assert(socket.connect(host, 23))
– c:settimeout(5)
local sres, serr = c:send(“>@R8012\r”)
print(“Send:”, sres, serr)
luup.call_delay(‘recieve_SYHDMIA1TO8’, 10)
end

function recieve_SYHDMIA1TO8()
local data, rerr = c:receive(100)
luup.log (data)
print (“Receive:”, data, rerr)
c:close()
end

send_SYHDMIA1TO8()
[/code]

Hold on, hold on, hold on

I can see the response in the logs now using the code above, ive been using LuaTest and that I assume stops after the first function is ended, it does not stay open untill the delayed action has been completed.

Ok, some progress, which is promising … ;D

Ok, a short update, I cant seem to capture the various responses that come back.

Ive tried the following variations, and so far I can only get some success when I specify an amount of characters to capture.

Ive altered the timeout too, to see if that works,

Any ideas ?

function recieve_SYHDMIA1TO8() luup.log ("????????????????- data is COMING NOW ????????????????") -- local data, rerr = c:receive('*a') -- does not work -- local data, rerr = c:receive('*l') -- does not work local data, rerr = c:receive(110) luup.log (data) print ("Receive:", data, rerr) c:settimeout(10) c:close() end

Just a long shot…

…you might take a look at the LuaSocket documentation here:

and, in particular, try:

c: setoption "tcp-nodelay"

after opening the socket and before doing anything else.

FYI, Nagle’s algorithm buffers I/O and can get in the way of alternate read/writes on a socket.