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

[Q] LrSocket as client

Contributor ,
Oct 20, 2017 Oct 20, 2017

Hi all,

I'm trying to connect existing server on localhost with LrSocket.

I mean Lightroom connects to the server.

Initiation is from Lightroom.

As I tried with some code, it seems LrSocket works only started with listening.

Is that correct?

I've read through, other thread.

Working with LRSocket, receiving

Following is modified test code from API doc.

test code

local LrSocket = import "LrSocket"
local LrTasks = import "LrTasks"
local LrFunctionContext = import "LrFunctionContext" -- hada added

import "LrTasks".startAsyncTask( function()

   LrFunctionContext.callWithContext( 'socket_remote', function( context )

   local running = true
   local sender = LrSocket.bind {

   functionContext = context,
   port = 33333, -- (let the OS assign the port)
  -- port = 0, -- (let the OS assign the port)
   plugin = _PLUGIN, -- hada added
   mode = "send",
   onConnecting = function( socket, port )

   -- TODO
   end,
   onConnected = function( socket, port )

   -- TODO
   end,
   onMessage = function( socket, message )

   -- nothing, we don't expect to get any messages back from a send port
   end,
   onClosed = function( socket )

   running = false
   end,
   onError = function( socket, err )

   if err == "timeout" then
   socket:reconnect()

   end
  end,
   }

   sender:send( "Hello world" )

   while running do
   LrTasks.sleep( 1/2 ) -- seconds
   end
   sender:close()

   end )

end )

TOPICS
SDK
687
Translate
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
no replies

Have something to add?

Join the conversation