Skip to main content
Participant
August 20, 2019
Answered

[LrSocket - Win10] Sending messages via sockets

  • August 20, 2019
  • 1 reply
  • 1799 views

Hi. I have the following problem, which leaves me somewhat flabbergasted.

I've loaded up the LrDevelopController sample plugin in Lightroom and written a c# counterpart to talk to it.

It works as expected, except I can't seem to send even a simple "hello world" string back to the external process.

Let me elaborate:

try

{

while (true)

{

   var buffer = new byte[1024];

   int received = _socket.Receive(buffer, SocketFlags.None);

   if (received == 0) return;

   var data = new byte[received];

   Array.Copy(buffer, data, received);

   var message = Encoding.ASCII.GetString(data);

   // This raises an event

   MessageReceived(message);

}

}

catch (Exception e)

{

Console.WriteLine(e);

}

Now, when I send a message to the plugin (via the appropriate c# sender socket), the plugin responds with "ok". So the Lr sender socket is actually working.

However, if I try a simple sender:send("hello world") ... nothing happens.

I've been digging around and I've found that I should actually append the strings with a new line in order for it to work - so i tried a /r/n. I even tried string.char(10)..string.char(13).

No dice.

This is the sender socket Lr code (I removed the observer, as I don't need automatic reporting of changes in the develop params).

local function makeSenderSocket( context )

  -- A socket connection that sends messages from the plugin to the external process.

  local sender = LrSocket.bind {

    functionContext = context,

      address = "localhost",

      port = sendPort,

      mode = "send",

      plugin = _PLUGIN,

      onConnecting = function( socket, port )

      senderPort = port

      maybeStartService()

      end,

      onConnected = function( socket, port )

      senderConnected = true

      end,

      onMessage = function( socket, message )

      -- Nothing, we don't expect to get any messages back.

      end,

      onClosed = function( socket )

      -- If the other side of this socket is closed,

      -- tell the run loop below that it should exit.

      _G.running = false

      end,

      onError = function( socket, err )

      if err == "timeout" then

        socket:reconnect()

      end

      end,

    }

    return sender

end

And I'm trying to get a reply like this: I send a message from c# in a key, value format and the event looks like:

if key == "sendMessage" then

   senderSocket:send( "Hello world\r\n" )

LrDialogs.showBezel( "fired", 1 )

    return true

  end

Lr shows the bezel, but the console output of the c# part looks like this

>>sent "sendMessage = true"

>>received "ok"

I'm at my wits end. Normally I would go like "f it" and use the observer, but I need to report more than simply the developer parameters, so I really need to send a couple of messages back to the c# app.

Would you kindly point me in the right direction?

This topic has been closed for replies.
Correct answer johnrellis

I think others have found that you need separate sockets for sending and receiving: Communication between a LR plugin and an iOS app over a LAN

Also, have you read the Lightroom Controller SDK Guide included in the SDK?  https://console.adobe.io/downloads/lr#

1 reply

johnrellis
johnrellisCorrect answer
Legend
August 20, 2019

I think others have found that you need separate sockets for sending and receiving: Communication between a LR plugin and an iOS app over a LAN

Also, have you read the Lightroom Controller SDK Guide included in the SDK?  https://console.adobe.io/downloads/lr#

Participant
August 20, 2019

Thanks for the reply.

1. Yes, I've read the docs. That's why I dont understand why it doesn't work.

2. Yes, I use two sets of sockets.

Yes, they both work, as I've stated in my question. I just can't seem to manually send a message. The only thing that lr says to my c# program are automated replies (the "ok" messages) and those replies are sent via the sender socket. I believe.

johnrellis
Legend
August 20, 2019

Maybe kimaldis​ or someone else with experience with LrSocket can chime in.