2 Replies Latest reply on Jul 12, 2016 8:26 PM by mattp75670702

    LrSocket running on Windows - problems


      Hi guys,
      I'm trying implement LrSocket communication with other processes using sockets on Windows 10 based system. I do have plugin and an app that runs on OSX and everything works great. Here is a code for server:


      function startServer(context)

        iLR.SERVER = LrSocket.bind {

          functionContext = context,

          plugin = _PLUGIN,

          port = 58764,

          mode = 'send',

          onClosed = function( socket )


          onError = function( socket, err )


          LrDialogs.message('error', err.tostring())


        onConnected = function( socket, port )

         LrDialogs.message( "Listener connected on port " .. port )





      it's not the firewall, i turned it off completely.

      However i cant make establish connection on windows. I used telnet, few more tools and nothing can even find specific port to be open.  I also tried every single example or plugins that other devs use, nothing seems to work. Can you guys can give any tips or maybe you have some experience with this matter that can be helpful to me.

      Thank you,


        • 1. Re: LrSocket running on Windows - problems
          johnrellis Most Valuable Participant

          I think the problem (or at least one problem) is that onError() calls err.tostring().  But "err" is a string, and err.tostring() will cause a Lua error.  Unfortunately, by default Lua errors that occur in tasks other than the main task or in SDK callbacks will terminate the calling task and be silently ignored -- you'll get no notification of the error.


          So when you execute your plugin, there isn't any client connected yet, and onError() will be called after a ten-second timeout.  This causes the silent Lua error, terminating the internal task listening on the socket.


          I strongly recommend that you use my Debugging Toolkit or you figure out how to connect an IDE debugger (described elsewhere in this forum).  Trying to debug LR Lua with print statements to a log file will just waste hours (more likely days) of your time.


          Here's a script that works on both Windows and Mac.  Run the script within LR, and then from a shell/command prompt, do "telnet localhost 4243".  The script will send "Hello world" to the telnet session and then close the connection.  The script also illustrates how to use the Debugging Toolkit to trap all errors:


          local Require = require 'Require'.path ("../common").reload ()
          local Debug = require 'Debug'.init ()
          require 'strict'
          local LrFunctionContext = import 'LrFunctionContext'
          local LrSocket = import 'LrSocket'
          local LrTasks = import 'LrTasks'
          local showErrors = Debug.showErrors
          local function main (context)
              local connected = false
              local socket = LrSocket.bind {
                  functionContext = context,
                  plugin = _PLUGIN,
                  port = 4243,
                  mode = 'send',
                  onClosed = showErrors (function (socket)
                      Debug.logn ("Closed")
                  onError = showErrors (function (socket, err)
                      Debug.logn ("Error", err) 
                  onConnecting = showErrors (function( socket, port )
                      Debug.logn ("Connecting on port", port)
                  onConnected = showErrors (function (socket, port)
                      connected = true
                      Debug.logn ("Connected on port", port)
              while not connected do LrTasks.sleep (0.1) end    
              socket:send ("Hello world\n")
              socket:close ()
          LrFunctionContext.postAsyncTaskWithContext ("main", 
              showErrors (function (context) main (context) end))
          • 2. Re: LrSocket running on Windows - problems
            mattp75670702 Level 1

            Thank you for your answer! i Installed debugging kit and yes, its saving me a lot! I was trying to debug through LrMessage, but it wasn't working for me. Your code works for me. Now i can continue working on my project!