Copy link to clipboard
Copied
I am creating an LR plugin to commuicate with my macOS app and am using LrSocket.
So far, I have successfully created the LrSocket to receive, but I am unable to get the send client to connect.
I am using a different port for each of them and am testing with the sample code provided by Adobe in the documentation as under:
local LrFunctionContext = import "LrFunctionContext"
local LrTasks = import 'LrTasks'
local LrSocket = import 'LrSocket'
local LrDialogs = import 'LrDialogs'
LrTasks.startAsyncTask( function()
LrFunctionContext.callWithContext( 'socket_remote', function( context )
local running = true
local sender = LrSocket.bind {
functionContext = context,
plugin = _PLUGIN,
port = 1235,
mode = "send",
onConnecting = function( socket, port )
LrDialogs.message("Connecting")
end,
onConnected = function( socket, port )
sender:send( "Hello world\n" )
LrDialogs.message(port)
end,
onMessage = function( socket, message )
end,
onClosed = function( socket )
running = false
end,
onError = function( socket, err )
if err == "timeout" then
socket:reconnect()
end
end,
}
sender:send( "Hello world\n" )
while running do
LrTasks.sleep( 1/2 ) -- seconds
end
sender:close()
end )
end )
The LrSocket just gets stuck on Connecting before timing out.
Can someone please guide as to what is going wrong?
Copy link to clipboard
Copied
It might be worth your while to look at URLHandler for talking to lightroom. I found the whole process a bunch easier than sockets. There's a reasonably good description in the SDK programmer's guide and Jeffrey Friedl fills in some fo the gaps hear: http://regex.info/blog/2012-01-17/1926.
Copy link to clipboard
Copied
I've never used LrSocket, but there are other threads here from developers describing how they got it to work (or not):
Copy link to clipboard
Copied
It's a pain, nearly everybody has problems with it to start. My main beef is that it forces you to send on one port, receive on another and you end up jumping through hoops trying to get the two to work together. URLHandler is much, much simpler. I suspect the performance may not be as good as sockets but for most of what I'm doing here it's working well and it makes it very easy to talk to apps like Bear and Obsidian. I'm currently using it with Bear to link collections to production notes.