0 Replies Latest reply on Oct 20, 2017 3:06 PM by Naoki-Hada

    [Q] LrSocket as client

    Naoki-Hada Level 1

      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 )