• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

[LrSocket - Win10] Sending messages via sockets

New Here ,
Aug 20, 2019 Aug 20, 2019

Copy link to clipboard

Copied

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?

TOPICS
SDK

Views

1.2K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Aug 20, 2019 Aug 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#

Votes

Translate

Translate
LEGEND ,
Aug 20, 2019 Aug 20, 2019

Copy link to clipboard

Copied

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#

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 20, 2019 Aug 20, 2019

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 20, 2019 Aug 20, 2019

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 20, 2019 Aug 20, 2019

Copy link to clipboard

Copied

c# typo.... an extra ! where it didnt belong.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 16, 2019 Sep 16, 2019

Copy link to clipboard

Copied

LATEST

It's a shame that the old posting were being removed.

I tried to disable the firewall on Windows 10, but i was not able to send a simple "hello world" from the lrsocket to my server.
The server was written in C++ and works when i use Python or telnet as the client.
It's only the sending stuff at the moment, so one socket should be enough in the first step

Any hints?

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines