[SDK] Send LrSockets acts as a server

Community Beginner ,
Nov 10, 2021 Nov 10, 2021

Copy link to clipboard

Copied

Hi,

 

So far I've managed to have a "Receive" LrSocket working in Lr. Now I want to have also a "Send" LrSocket. I've based my code on the documentation and some examples from this forum, but for whatever reason it only acts like a "Receive" socket : it doesn't connect to my server (which works, tested with netcat), but accepts incoming connections... like a server.

 

During my tests the "Receive" LrSocket is not activated, so no mistake here... Do you guys have an idea?

 

Here is the code:

local function setupSendSocket()
        LrTasks.startAsyncTask(function()
            LrFunctionContext.callWithContext("socket_send", function(context)
                outputToLog("Setting up send socket")
                local running = true
                local errors = 0
                local socket = LrSocket.bind {
                    plugin = _PLUGIN,
                    functionContext = context,
                    port = 19700,
                    mode = 'send',
                    onClosed =  function (socket)
                        outputToLog("Closed")
                        --running = false
                    end,
                    onError = function (socket, err)
                        errors = errors + 1
                        outputToLog("Error: " .. err) 
                        isConnected = false
                        if errors > 2 then
                            running = false
                        else
                            socket:reconnect()
                        end
                    end,
                    onConnecting = function( socket, port )
                        outputToLog("Connection to port " .. port)
                    end,
                    onConnected = function (socket, port)
                        outputToLog("Connected!")
                        isConnected = true
                        errors = 0
                        socket:send("TEST2\n")
                    end}
                outputToLog("Socket Receive set up")
                socket:send("TEST\n")
                while running do LrTasks.sleep (0.1) end    
                socket:close ()
            end )
        end )
    end
TOPICS
SDK

Views

20

Likes

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
no replies

Have something to add?

Join the conversation