Working with LRSocket, receiving
I'm trying to set up a communication between Lightroom and another process using LRSocket. I've worked out an LrSocket.bind with mode = "send" and that's all working fine but I cannot for the life of me get a receive working. Here's my Lua code:
Connection = {
}
function Connection.Listen( self, context )
local running = true
self.Listener = LrSocket.bind {
functionContext = context,
port = 4242,
plugin = _PLUGIN,
mode = "receive",
onConnected = function( socket, port )
Debug.logn( "Listener connected on port " .. port )
end,
onMessage = function( socket, message )
Debug.logn( "Listener Got: " .. message );
end,
onClosed = function( socket )
Debug.logn( "Listener Closed on Port: " .. myPort )
running = false
end,
onError = function( socket, err )
if err == "timeout" then
end
end,
} -- bind
while running do
LrTasks.sleep( 1/2 ) -- seconds
end
self.Listener:close()
end
I've been testing with both telnet and a short python snippet shown below. Telnet fails to connect at all, the Python code connects and the onConnected callback is called but, although text is being sent, the onMessage callback doesn't get called. I wondered if anyone had managed to make this work at all or if anyone has any pointers on what might be going wrong.
import socket, select, sys, time
def Send( msg 😞
TCP_IP = 'localhost'
TCP_PORT = 4242
BUFFER_SIZE = 1024
MESSAGE = "Hello, World!"
print "Sending on port ", TCP_PORT
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(2)
s.connect((TCP_IP, TCP_PORT))
s.send(MESSAGE)
print "Sent"
s.close()
time.sleep( 5 )
print "Closed"
Send( "Test")
Many thanks.
